Skip to content

Commit

Permalink
CAMEL-11237: camel-grpc consumer finalization and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvolod committed May 22, 2017
1 parent 5722668 commit 3025f91
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
8 changes: 4 additions & 4 deletions components/camel-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
<version>${javassist-version}</version>
</dependency>

<!-- for testing -->
Expand All @@ -79,7 +79,7 @@
<dependency>
<groupId>com.googlecode.junit-toolbox</groupId>
<artifactId>junit-toolbox</artifactId>
<version>2.3</version>
<version>${junit-toolbox-version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -112,7 +112,7 @@
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
<version>${os-maven-plugin-version}</version>
</extension>
</extensions>

Expand Down Expand Up @@ -159,7 +159,7 @@
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<version>${protobuf-maven-plugin-version}</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf-version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
Expand Down
30 changes: 25 additions & 5 deletions components/camel-grpc/src/main/docs/grpc-component.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*Available as of Camel version 2.19*

The gRPC component allows you to do Remote Procedure Call (RPC)
The gRPC component allows you to call or expose Remote Procedure Call (RPC) services
using https://developers.google.com/protocol-buffers/docs/overview[Protocol Buffers (protobuf)]
exchange format over HTTP/2 transport.

Expand Down Expand Up @@ -55,7 +55,7 @@ with the following path and query parameters:
| **host** (common) | The gRPC server host name | | String
| **port** (common) | The gRPC server port | | int
| **bridgeErrorHandler** (consumer) | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN or ERROR level and ignored. | false | boolean
| **processingStrategy** (consumer) | TBD | | GrpcProcessing Strategies
| **processingStrategy** (consumer) | This option specifies the top-level strategy for processing service requests and responses in streaming mode. If an aggregation strategy is selected all requests will be accumulated in the list then transferred to the flow and the accumulated responses will be sent to the sender. If a propagation strategy is selected request is sent to the stream and the response will be immediately sent back to the sender. | | GrpcProcessing Strategies
| **exceptionHandler** (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN or ERROR level and ignored. | | ExceptionHandler
| **exchangePattern** (consumer) | Sets the exchange pattern when the consumer creates an exchange. | | ExchangePattern
| **method** (producer) | gRPC method name | | String
Expand Down Expand Up @@ -85,6 +85,18 @@ The table below shows the types of objects in the message body, depending on the

|=======================================================================

### gRPC consumer headers (will be installed after the consumer invocation)

[width="100%",cols="25%,50,25%",options="header",]
|=======================================================================
|Header name |Description|Possible values

|*CamelGrpcMethodName*|Method name handled by the consumer service|
|*CamelGrpcEventType*|Received event type from the sended request|onNext, onCompleted or onError
|*CamelGrpcUserAgent*|If provided, the given agent will prepend the gRPC library's user agent information|

|=======================================================================

### Examples

Below is a simple synchronous method invoke with host and port parameters
Expand All @@ -107,10 +119,18 @@ An asynchronous method invoke with target host and port parameter

[source,java]
-------------------------------------------------------------------------------
from("direct:index")
from("direct:grpc-async")
.to("grpc://org.apache.camel.component.grpc.PingPong?method=pingAsyncResponse&target=dns:///hostname:8000");
-------------------------------------------------------------------------------

gRPC service consumer with propagation processing strategy

[source,java]
-------------------------------------------------------------------------------
from("grpc://org.apache.camel.component.grpc.PingPong??processingStrategy=PROPAGATION&host=localhost&port=1000")
.to("direct:grpc-service");
-------------------------------------------------------------------------------

It's it is recommended to use Maven Protocol Buffers Plugin which calls Protocol Buffer Compiler (protoc) tool to generate Java source files from .proto (protocol buffer definition) files for the custom project. This plugin will generate procedures request and response classes, their builders and gRPC procedures stubs classes as well.

Following steps are required:
Expand All @@ -135,9 +155,9 @@ Insert gRPC and protobuf Java code generator plugin **<plugins>** tag of the pro
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:${protobuf-version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier}</pluginArtifact>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GrpcConfiguration {

/**
* Fully qualified service name from the protocol buffer descriptor file
* (package dot service definition name)
* (package dot service definition name)
*/
public String getService() {
return service;
Expand Down Expand Up @@ -111,7 +111,12 @@ public void setUsePlainText(Boolean usePlainText) {
}

/**
* TBD
* This option specifies the top-level strategy for processing service
* requests and responses in streaming mode. If an aggregation strategy is
* selected, all requests will be accumulated in the list, then transferred
* to the flow, and the accumulated responses will be sent to the sender. If
* a propagation strategy is selected, request is sent to the stream, and the
* response will be immediately sent back to the sender.
*/
public GrpcProcessingStrategies getProcessingStrategy() {
return processingStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.grpc.GrpcConsumerConcurrentTest.PongResponseStreamObserver;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.After;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
*/
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.builder.RouteBuilder;
import org.apache.camel.component.grpc.GrpcConsumerAggregationTest.GrpcMessageBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit4.CamelTestSupport;
Expand All @@ -44,7 +41,6 @@ public class GrpcConsumerPropagationTest extends CamelTestSupport {
private static final String GRPC_TEST_PONG_VALUE = "PONG";

private ManagedChannel asyncRequestChannel;
private PingPongGrpc.PingPongStub nonBlockingStub;
private PingPongGrpc.PingPongStub asyncNonBlockingStub;

@Before
Expand Down
4 changes: 4 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
<javacrumbs-version>0.22</javacrumbs-version>
<javapoet-version>1.8.0</javapoet-version>
<javassist-bundle-version>3.12.1.GA_3</javassist-bundle-version>
<javassist-version>3.20.0-GA</javassist-version>
<javax.el-api-version>2.2.5</javax.el-api-version>
<javax.el-version>2.2.5</javax.el-version>
<javax-inject-bundle-version>1_2</javax-inject-bundle-version>
Expand Down Expand Up @@ -397,6 +398,7 @@
<juel-version>2.1.3</juel-version>
<!-- camel-itest-karaf doesn't work with JUnit 4.12 at present -->
<junit-bundle-version>4.11_1</junit-bundle-version>
<junit-toolbox-version>2.3</junit-toolbox-version>
<junit-version>4.12</junit-version>
<jxmpp-version>0.5.0</jxmpp-version>
<jython-version>2.5.3</jython-version>
Expand Down Expand Up @@ -510,6 +512,7 @@
<ops4j-base-version>1.5.0</ops4j-base-version>
<optaplanner-version>6.5.0.Final</optaplanner-version>
<oro-bundle-version>2.0.8_6</oro-bundle-version>
<os-maven-plugin-version>1.4.1.Final</os-maven-plugin-version>
<oscache-bundle-version>2.4_5</oscache-bundle-version>
<osgi-version>4.3.1</osgi-version>
<paho-version>1.1.0</paho-version>
Expand All @@ -523,6 +526,7 @@
<powermock-version>1.6.6</powermock-version>
<protobuf-version>3.1.0</protobuf-version>
<protobuf-guava-version>18.0</protobuf-guava-version>
<protobuf-maven-plugin-version>0.5.0</protobuf-maven-plugin-version>
<pubnub-version>4.6.2</pubnub-version>
<qpid-bundle-version>0.28_1</qpid-bundle-version>
<qpid-proton-j-version>0.16.0</qpid-proton-j-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* The gRPC component is using for calling remote procedures via HTTP/2
* The gRPC component allows to call and expose remote procedures via HTTP/2
* with protobuf dataformat
*
* Generated by camel-package-maven-plugin - do not edit this file!
*/
Expand Down

0 comments on commit 3025f91

Please sign in to comment.