-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend test coverage of gRPC extension
Fixes #5155
- Loading branch information
1 parent
df2bc76
commit 01f624f
Showing
15 changed files
with
732 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
=== Integration with Quarkus gRPC is not supported | ||
|
||
At present there is no support for integrating Camel Quarkus gRPC with Quarkus gRPC. If you have both the `camel-quarkus-grpc` and `quarkus-grpc` extension dependency on the classpath, you are likely to encounter problems at build time when compiling your application. | ||
|
||
=== Protobuf generated code | ||
|
||
You can https://github.com/grpc/grpc-java#generated-code[generate] gRPC service stubs with protobuf. A limitation of this is that generated code is annotated with the non Jakarta EE 10 friendly `@javax.annotation.Generated`. | ||
|
||
To avoid compilation issues, the `grpc-java` project recommendation is to add a `provided` scoped dependency like this: | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>annotations-api</artifactId> | ||
<version>6.0.53</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
---- | ||
|
||
Alternatively, you can use Maven or Gradle plugins to iterate over the generated code (found at `target/generated-sources` for Maven) and replace all instances of `@javax.annotation.Generated` with `@jakarta.annotation.Generated`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
=== Protobuf generated code | ||
|
||
You can https://github.com/grpc/grpc-java#generated-code[generate] gRPC service stubs with protobuf. | ||
|
||
==== protobuf-maven-plugin | ||
|
||
The `protobuf-maven-plugin` can generate service stubs for `.proto` files. Below is an example configuration for Maven. | ||
|
||
[source,xml] | ||
---- | ||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>kr.motd.maven</groupId> | ||
<artifactId>os-maven-plugin</artifactId> | ||
<version>{os-maven-plugin-version}</version> | ||
</extension> | ||
</extensions> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.xolstice.maven.plugins</groupId> | ||
<artifactId>protobuf-maven-plugin</artifactId> | ||
<version>{protobuf-maven-plugin-version}</version> | ||
<configuration> | ||
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact> | ||
<pluginId>grpc-java</pluginId> | ||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>compile-custom</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<goals> | ||
<goal>test-compile</goal> | ||
<goal>test-compile-custom</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
---- | ||
|
||
==== Generated code limitations | ||
|
||
A limitation of the generated code is that it is annotated with the non Jakarta EE 10 friendly `@javax.annotation.Generated`. | ||
|
||
To avoid compilation issues, the `grpc-java` project recommendation is to add a `provided` scoped dependency like this: | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>annotations-api</artifactId> | ||
<version>6.0.53</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
---- | ||
|
||
Alternatively, you can use Maven or Gradle plugins to iterate over the generated code (found at `target/generated-sources` for Maven) and replace all instances of `@javax.annotation.Generated` with `@jakarta.annotation.Generated`. | ||
|
||
=== Accessing classpath resources in native mode | ||
|
||
The gRPC component has various options where resources are resolved from the classpath: | ||
|
||
* `keyCertChainResource` | ||
* `keyResource` | ||
* `serviceAccountResource` | ||
* `trustCertCollectionResource` | ||
|
||
When using these options in native mode, you must ensure that any such resources are included in the native image. | ||
|
||
This can be accomplished by adding the configuration property `quarkus.native.resources.includes` to `application.properties`. | ||
For example, to include SSL / TLS keys and certificates. | ||
|
||
[source,properties] | ||
---- | ||
quarkus.native.resources.includes = certs/*.pem,certs.*.key | ||
---- | ||
|
||
More information about selecting resources for inclusion in the native executable can be found in the xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[native mode guide]. |
44 changes: 44 additions & 0 deletions
44
...rpc/src/main/java/org/apache/camel/quarkus/component/grpc/it/CustomClientInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.quarkus.component.grpc.it; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@Named | ||
public class CustomClientInterceptor implements ClientInterceptor { | ||
public static final Metadata.Key<String> PING_ID = Metadata.Key.of("pingId", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, | ||
Channel next) { | ||
return new ForwardingClientCall.SimpleForwardingClientCall<>(next.newCall(method, callOptions)) { | ||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
headers.put(PING_ID, "100"); | ||
super.start(responseListener, headers); | ||
} | ||
}; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rpc/src/main/java/org/apache/camel/quarkus/component/grpc/it/CustomServerInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.quarkus.component.grpc.it; | ||
|
||
import io.grpc.Context; | ||
import io.grpc.Contexts; | ||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@Named | ||
public class CustomServerInterceptor implements ServerInterceptor { | ||
public static final Context.Key<String> RESPONSE_KEY = Context.key("consumer-response"); | ||
public static final Context.Key<String> PING_ID_CONTEXT_KEY = Context.key("pingId"); | ||
public static final Metadata.Key<String> PING_ID_METADATA_KEY = Metadata.Key.of("pingId", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( | ||
ServerCall<ReqT, RespT> call, | ||
Metadata headers, | ||
ServerCallHandler<ReqT, RespT> next) { | ||
Context context = Context.current() | ||
.withValue(PING_ID_CONTEXT_KEY, headers.get(PING_ID_METADATA_KEY)) | ||
.withValue(RESPONSE_KEY, " PONG"); | ||
return Contexts.interceptCall(context, call, headers, next); | ||
} | ||
} |
Oops, something went wrong.