You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/10/24 14:06:02 UTC
[GitHub] [camel] rajasekharb opened a new pull request #4508: Control response stream via camel route
rajasekharb opened a new pull request #4508:
URL: https://github.com/apache/camel/pull/4508
- [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
- [ ] Each commit in the pull request should have a meaningful subject line and body.
- [ ] If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Run `mvn clean install -Psourcecheck` in your module with source check enabled to make sure basic checks pass and there are no checkstyle violations. A more thorough check will be performed on your pull request automatically.
Below are the contribution guidelines:
https://github.com/apache/camel/blob/master/CONTRIBUTING.md
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511863809
##########
File path: components/camel-grpc/src/test/java/org/apache/camel/component/grpc/RouteControlledStreamObserverTest.java
##########
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.grpc;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import io.grpc.stub.StreamObserver;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class RouteControlledStreamObserverTest extends CamelTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GrpcConsumerAggregationTest.class);
+
+ private static final int GRPC_SYNC_REQUEST_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int GRPC_ASYNC_REQUEST_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int GRPC_TEST_PING_ID = 1;
+ private static final String GRPC_TEST_PING_VALUE = "PING";
+ private static final String GRPC_TEST_PONG_VALUE = "PONG";
+
+ private ManagedChannel syncRequestChannel;
+ private ManagedChannel asyncRequestChannel;
+ private PingPongGrpc.PingPongBlockingStub blockingStub;
+ private PingPongGrpc.PingPongStub nonBlockingStub;
+ private PingPongGrpc.PingPongStub asyncNonBlockingStub;
+
+ @BeforeEach
+ public void startGrpcChannels() {
+ syncRequestChannel = ManagedChannelBuilder.forAddress("localhost", GRPC_SYNC_REQUEST_TEST_PORT).usePlaintext().build();
+ asyncRequestChannel
+ = ManagedChannelBuilder.forAddress("localhost", GRPC_ASYNC_REQUEST_TEST_PORT).usePlaintext().build();
+ blockingStub = PingPongGrpc.newBlockingStub(syncRequestChannel);
+ nonBlockingStub = PingPongGrpc.newStub(syncRequestChannel);
+ asyncNonBlockingStub = PingPongGrpc.newStub(asyncRequestChannel);
+ }
+
+ @AfterEach
+ public void stopGrpcChannels() {
+ syncRequestChannel.shutdown().shutdownNow();
+ asyncRequestChannel.shutdown().shutdownNow();
+ }
+
+ @Test
+ public void testSyncSyncMethodInSync() {
+ LOG.info("gRPC pingSyncSync method blocking test start");
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponse pongResponse = blockingStub.pingSyncSync(pingRequest);
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testSyncAsyncMethodInSync() {
+ LOG.info("gRPC pingSyncAsync method blocking test start");
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ Iterator<PongResponse> pongResponseIter = blockingStub.pingSyncAsync(pingRequest);
+ while (pongResponseIter.hasNext()) {
+ PongResponse pongResponse = pongResponseIter.next();
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+ }
+
+ @Test
+ public void testSyncSyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingSyncSync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ nonBlockingStub.pingSyncSync(pingRequest, responseObserver);
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testSyncAsyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingSyncAsync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ nonBlockingStub.pingSyncAsync(pingRequest, responseObserver);
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testAsyncSyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingAsyncSync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ StreamObserver<PingRequest> requestObserver = asyncNonBlockingStub.pingAsyncSync(responseObserver);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onCompleted();
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testAsyncAsyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingAsyncAsync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ StreamObserver<PingRequest> requestObserver = asyncNonBlockingStub.pingAsyncAsync(responseObserver);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onCompleted();
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ private void process(Exchange exchange) {
+ Message message = exchange.getIn();
+ PingRequest pingRequest = message.getBody(PingRequest.class);
+ StreamObserver<Object> responseObserver = (StreamObserver<Object>) exchange.getProperty("responseObserver");
+ PongResponse pongResponse
+ = PongResponse.newBuilder().setPongName(pingRequest.getPingName() + GRPC_TEST_PONG_VALUE)
+ .setPongId(pingRequest.getPingId()).build();
+ message.setBody(pongResponse, PongResponse.class);
+ exchange.setMessage(message);
+ responseObserver.onNext(pongResponse);
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void configure() {
+ from("grpc://localhost:" + GRPC_SYNC_REQUEST_TEST_PORT
+ + "/org.apache.camel.component.grpc.PingPong?synchronous=true&consumerStrategy=PROPAGATION&routeControlledStreamObserver=true")
+ .process(this::process);
+
+ from("grpc://localhost:" + GRPC_ASYNC_REQUEST_TEST_PORT
+ + "/org.apache.camel.component.grpc.PingPong?synchronous=true&consumerStrategy=AGGREGATION")
Review comment:
Agree. Included a failure test case and added a check in the GrpcConsumer to prevent server start event in case of incorrect configuration.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] dmvolod commented on pull request #4508: Control response stream via camel route
Posted by GitBox <gi...@apache.org>.
dmvolod commented on pull request #4508:
URL: https://github.com/apache/camel/pull/4508#issuecomment-716110386
@rajasekharb please update PR title and scope of code according discussion in Jira.
Also wood like to have an option for propogating streamObserver and not always and not based on property as it not explicit.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511764655
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -39,19 +39,30 @@ public GrpcMethodHandler(GrpcConsumer consumer) {
this.consumer = consumer;
}
+ /**
+ * This method deals with the unary and server streaming gRPC calls
+ *
+ * @param body The request object sent by the gRPC client to the server
+ * @param responseObserver The response stream observer
+ * @param methodName The name of the method invoked using the stub.
+ * @throws Exception java.lang.Exception
+ */
public void handle(Object body, StreamObserver<Object> responseObserver, String methodName) throws Exception {
Map<String, Object> grcpHeaders = populateGrpcHeaders(methodName);
GrpcEndpoint endpoint = (GrpcEndpoint) consumer.getEndpoint();
+
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody(body);
exchange.getIn().setHeaders(grcpHeaders);
- if (endpoint.isSynchronous()) {
- consumer.getProcessor().process(exchange);
- } else {
- consumer.getAsyncProcessor().process(exchange);
+ if (endpoint.getConfiguration().isRouteControlledStreamObserver()) {
+ exchange.setProperty("responseObserver", responseObserver);
Review comment:
I agree. Have set, a constant in GrpcConstants.java.
String GRPC_STREAM_OBSERVER = "grpcResponseObserver";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] dmvolod commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
dmvolod commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511732925
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcConfiguration.java
##########
@@ -353,15 +356,33 @@ public void setFlowControlWindow(int flowControlWindow) {
this.flowControlWindow = flowControlWindow;
}
+ public int getMaxMessageSize() {
+ return maxMessageSize;
+ }
+
/**
* The maximum message size allowed to be received/sent (MiB)
*/
public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}
- public int getMaxMessageSize() {
- return maxMessageSize;
+ /**
+ * Lets the camel route to take control over stream observer. If this value is set to true, then the stream
Review comment:
Camel must be in CamelCase as it's project name but also redundant :smile:
Also name of the property must be documented or separate micro example can be provided.
Please don't forget about constant described below. Info about default false value as also redundant as it always false by default.
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -39,19 +39,30 @@ public GrpcMethodHandler(GrpcConsumer consumer) {
this.consumer = consumer;
}
+ /**
+ * This method deals with the unary and server streaming gRPC calls
+ *
+ * @param body The request object sent by the gRPC client to the server
+ * @param responseObserver The response stream observer
+ * @param methodName The name of the method invoked using the stub.
+ * @throws Exception java.lang.Exception
+ */
public void handle(Object body, StreamObserver<Object> responseObserver, String methodName) throws Exception {
Map<String, Object> grcpHeaders = populateGrpcHeaders(methodName);
GrpcEndpoint endpoint = (GrpcEndpoint) consumer.getEndpoint();
+
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody(body);
exchange.getIn().setHeaders(grcpHeaders);
- if (endpoint.isSynchronous()) {
- consumer.getProcessor().process(exchange);
- } else {
- consumer.getAsyncProcessor().process(exchange);
+ if (endpoint.getConfiguration().isRouteControlledStreamObserver()) {
+ exchange.setProperty("responseObserver", responseObserver);
Review comment:
@rajasekharb would be nice to store this value in constants and give a name like `grpcResponseObserver` as generic name `responseObserver` can be intersected with other components property.
##########
File path: components/camel-grpc/src/test/java/org/apache/camel/component/grpc/RouteControlledStreamObserverTest.java
##########
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.grpc;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import io.grpc.stub.StreamObserver;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class RouteControlledStreamObserverTest extends CamelTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GrpcConsumerAggregationTest.class);
+
+ private static final int GRPC_SYNC_REQUEST_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int GRPC_ASYNC_REQUEST_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int GRPC_TEST_PING_ID = 1;
+ private static final String GRPC_TEST_PING_VALUE = "PING";
+ private static final String GRPC_TEST_PONG_VALUE = "PONG";
+
+ private ManagedChannel syncRequestChannel;
+ private ManagedChannel asyncRequestChannel;
+ private PingPongGrpc.PingPongBlockingStub blockingStub;
+ private PingPongGrpc.PingPongStub nonBlockingStub;
+ private PingPongGrpc.PingPongStub asyncNonBlockingStub;
+
+ @BeforeEach
+ public void startGrpcChannels() {
+ syncRequestChannel = ManagedChannelBuilder.forAddress("localhost", GRPC_SYNC_REQUEST_TEST_PORT).usePlaintext().build();
+ asyncRequestChannel
+ = ManagedChannelBuilder.forAddress("localhost", GRPC_ASYNC_REQUEST_TEST_PORT).usePlaintext().build();
+ blockingStub = PingPongGrpc.newBlockingStub(syncRequestChannel);
+ nonBlockingStub = PingPongGrpc.newStub(syncRequestChannel);
+ asyncNonBlockingStub = PingPongGrpc.newStub(asyncRequestChannel);
+ }
+
+ @AfterEach
+ public void stopGrpcChannels() {
+ syncRequestChannel.shutdown().shutdownNow();
+ asyncRequestChannel.shutdown().shutdownNow();
+ }
+
+ @Test
+ public void testSyncSyncMethodInSync() {
+ LOG.info("gRPC pingSyncSync method blocking test start");
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponse pongResponse = blockingStub.pingSyncSync(pingRequest);
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testSyncAsyncMethodInSync() {
+ LOG.info("gRPC pingSyncAsync method blocking test start");
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ Iterator<PongResponse> pongResponseIter = blockingStub.pingSyncAsync(pingRequest);
+ while (pongResponseIter.hasNext()) {
+ PongResponse pongResponse = pongResponseIter.next();
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+ }
+
+ @Test
+ public void testSyncSyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingSyncSync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ nonBlockingStub.pingSyncSync(pingRequest, responseObserver);
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testSyncAsyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingSyncAsync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ nonBlockingStub.pingSyncAsync(pingRequest, responseObserver);
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testAsyncSyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingAsyncSync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ StreamObserver<PingRequest> requestObserver = asyncNonBlockingStub.pingAsyncSync(responseObserver);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onCompleted();
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Test
+ public void testAsyncAsyncMethodInAsync() throws Exception {
+ LOG.info("gRPC pingAsyncAsync method async test start");
+ final CountDownLatch latch = new CountDownLatch(1);
+ PingRequest pingRequest
+ = PingRequest.newBuilder().setPingName(GRPC_TEST_PING_VALUE).setPingId(GRPC_TEST_PING_ID).build();
+ PongResponseStreamObserver responseObserver = new PongResponseStreamObserver(latch);
+
+ StreamObserver<PingRequest> requestObserver = asyncNonBlockingStub.pingAsyncAsync(responseObserver);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onNext(pingRequest);
+ requestObserver.onCompleted();
+ latch.await(5, TimeUnit.SECONDS);
+
+ PongResponse pongResponse = responseObserver.getPongResponse();
+
+ assertNotNull(pongResponse);
+ assertEquals(GRPC_TEST_PING_ID, pongResponse.getPongId());
+ assertEquals(GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE, pongResponse.getPongName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ private void process(Exchange exchange) {
+ Message message = exchange.getIn();
+ PingRequest pingRequest = message.getBody(PingRequest.class);
+ StreamObserver<Object> responseObserver = (StreamObserver<Object>) exchange.getProperty("responseObserver");
+ PongResponse pongResponse
+ = PongResponse.newBuilder().setPongName(pingRequest.getPingName() + GRPC_TEST_PONG_VALUE)
+ .setPongId(pingRequest.getPingId()).build();
+ message.setBody(pongResponse, PongResponse.class);
+ exchange.setMessage(message);
+ responseObserver.onNext(pongResponse);
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void configure() {
+ from("grpc://localhost:" + GRPC_SYNC_REQUEST_TEST_PORT
+ + "/org.apache.camel.component.grpc.PingPong?synchronous=true&consumerStrategy=PROPAGATION&routeControlledStreamObserver=true")
+ .process(this::process);
+
+ from("grpc://localhost:" + GRPC_ASYNC_REQUEST_TEST_PORT
+ + "/org.apache.camel.component.grpc.PingPong?synchronous=true&consumerStrategy=AGGREGATION")
Review comment:
Seems to routeControlledStreamObserver=true and consumerStrategy=AGGREGATION not compatible. We should notify that option will be ignored and not applied or just fail route start as it cause unpredictable result.
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -62,16 +73,29 @@ public void handle(Object body, StreamObserver<Object> responseObserver, String
Object responseBody = exchange.getIn().getBody();
if (responseBody instanceof List) {
List<Object> responseList = (List<Object>) responseBody;
- responseList.forEach(responseItem -> {
- responseObserver.onNext(responseItem);
- });
+ responseList.forEach(responseObserver::onNext);
} else {
responseObserver.onNext(responseBody);
}
responseObserver.onCompleted();
}
}
+ private void invokeCamelRoute(GrpcEndpoint endpoint, Exchange exchange) throws Exception {
Review comment:
Camel in this name is redundant. Let's call this function as
```suggestion
private void invokeRoute(GrpcEndpoint endpoint, Exchange exchange) throws Exception {
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511764655
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -39,19 +39,30 @@ public GrpcMethodHandler(GrpcConsumer consumer) {
this.consumer = consumer;
}
+ /**
+ * This method deals with the unary and server streaming gRPC calls
+ *
+ * @param body The request object sent by the gRPC client to the server
+ * @param responseObserver The response stream observer
+ * @param methodName The name of the method invoked using the stub.
+ * @throws Exception java.lang.Exception
+ */
public void handle(Object body, StreamObserver<Object> responseObserver, String methodName) throws Exception {
Map<String, Object> grcpHeaders = populateGrpcHeaders(methodName);
GrpcEndpoint endpoint = (GrpcEndpoint) consumer.getEndpoint();
+
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody(body);
exchange.getIn().setHeaders(grcpHeaders);
- if (endpoint.isSynchronous()) {
- consumer.getProcessor().process(exchange);
- } else {
- consumer.getAsyncProcessor().process(exchange);
+ if (endpoint.getConfiguration().isRouteControlledStreamObserver()) {
+ exchange.setProperty("responseObserver", responseObserver);
Review comment:
I agree. Have set a constant in GrpcConstants.java.
String GRPC_STREAM_OBSERVER = "grpcResponseObserver";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] dmvolod commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
dmvolod commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511732925
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcConfiguration.java
##########
@@ -353,15 +356,33 @@ public void setFlowControlWindow(int flowControlWindow) {
this.flowControlWindow = flowControlWindow;
}
+ public int getMaxMessageSize() {
+ return maxMessageSize;
+ }
+
/**
* The maximum message size allowed to be received/sent (MiB)
*/
public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}
- public int getMaxMessageSize() {
- return maxMessageSize;
+ /**
+ * Lets the camel route to take control over stream observer. If this value is set to true, then the stream
Review comment:
Camel must be in CamelCase as it's project name but also a bit redundant :smile:
Also name of the property must be documented or separate micro example can be provided.
Please don't forget about constant described below. Info about default false value as also redundant as it always false by default.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511764742
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -62,16 +73,29 @@ public void handle(Object body, StreamObserver<Object> responseObserver, String
Object responseBody = exchange.getIn().getBody();
if (responseBody instanceof List) {
List<Object> responseList = (List<Object>) responseBody;
- responseList.forEach(responseItem -> {
- responseObserver.onNext(responseItem);
- });
+ responseList.forEach(responseObserver::onNext);
} else {
responseObserver.onNext(responseBody);
}
responseObserver.onCompleted();
}
}
+ private void invokeCamelRoute(GrpcEndpoint endpoint, Exchange exchange) throws Exception {
Review comment:
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on pull request #4508:
URL: https://github.com/apache/camel/pull/4508#issuecomment-716462379
Created a new branch and gave PR. Please refer below link. Closing the current PR
https://github.com/apache/camel/pull/4515
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511764655
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/server/GrpcMethodHandler.java
##########
@@ -39,19 +39,30 @@ public GrpcMethodHandler(GrpcConsumer consumer) {
this.consumer = consumer;
}
+ /**
+ * This method deals with the unary and server streaming gRPC calls
+ *
+ * @param body The request object sent by the gRPC client to the server
+ * @param responseObserver The response stream observer
+ * @param methodName The name of the method invoked using the stub.
+ * @throws Exception java.lang.Exception
+ */
public void handle(Object body, StreamObserver<Object> responseObserver, String methodName) throws Exception {
Map<String, Object> grcpHeaders = populateGrpcHeaders(methodName);
GrpcEndpoint endpoint = (GrpcEndpoint) consumer.getEndpoint();
+
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody(body);
exchange.getIn().setHeaders(grcpHeaders);
- if (endpoint.isSynchronous()) {
- consumer.getProcessor().process(exchange);
- } else {
- consumer.getAsyncProcessor().process(exchange);
+ if (endpoint.getConfiguration().isRouteControlledStreamObserver()) {
+ exchange.setProperty("responseObserver", responseObserver);
Review comment:
I agree. Have set a constant in GrpcConstants.java.
String GRPC_RESPONSE_OBSERVER = "grpcResponseObserver";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb commented on a change in pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb commented on a change in pull request #4508:
URL: https://github.com/apache/camel/pull/4508#discussion_r511862988
##########
File path: components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcConfiguration.java
##########
@@ -353,15 +356,33 @@ public void setFlowControlWindow(int flowControlWindow) {
this.flowControlWindow = flowControlWindow;
}
+ public int getMaxMessageSize() {
+ return maxMessageSize;
+ }
+
/**
* The maximum message size allowed to be received/sent (MiB)
*/
public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}
- public int getMaxMessageSize() {
- return maxMessageSize;
+ /**
+ * Lets the camel route to take control over stream observer. If this value is set to true, then the stream
Review comment:
I agree. Made the relevant changes as per the conversation on zulip chat
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel] rajasekharb closed pull request #4508: CAMEL-15751 Base improvement to provide access to stream observer in the camel Exchange
Posted by GitBox <gi...@apache.org>.
rajasekharb closed pull request #4508:
URL: https://github.com/apache/camel/pull/4508
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org