You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/11/20 12:38:05 UTC
[camel-quarkus] 03/03: Protobuf dataformat native support #789
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 181d86bf89c6835a308f77e6b6d3801e72dcbea5
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Fri Nov 20 11:39:58 2020 +0100
Protobuf dataformat native support #789
---
.../ROOT/pages/reference/extensions/protobuf.adoc | 37 +++++++++--
.../partials/reference/dataformats/protobuf.adoc | 6 +-
extensions-jvm/pom.xml | 1 -
extensions/pom.xml | 1 +
.../protobuf/deployment/pom.xml | 6 ++
.../protobuf/deployment/ProtobufProcessor.java | 35 +++++++----
{extensions-jvm => extensions}/protobuf/pom.xml | 1 -
.../protobuf/runtime/pom.xml | 2 +-
.../runtime/src/main/doc/configuration.adoc | 25 ++++++++
.../main/resources/META-INF/quarkus-extension.yaml | 0
integration-tests/pom.xml | 1 +
.../protobuf}/pom.xml | 73 +++++++++++-----------
.../component/protobuf/it/ProtobufResource.java | 0
.../component/protobuf/it/ProtobufRoute.java | 0
.../protobuf}/src/main/proto/addressbook.proto | 0
.../quarkus/component/protobuf/it/ProtobufIT.java | 17 +----
.../component/protobuf/it/ProtobufTest.java | 0
tooling/scripts/test-categories.yaml | 1 +
18 files changed, 134 insertions(+), 72 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc b/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
index 01cba4b..78c4894 100644
--- a/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
@@ -3,15 +3,15 @@
= Protobuf
:page-aliases: extensions/protobuf.adoc
:cq-artifact-id: camel-quarkus-protobuf
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-description: Serialize and deserialize Java objects using Google's Protocol buffers.
:cq-deprecated: false
:cq-jvm-since: 1.0.0
-:cq-native-since: 1.0.0
+:cq-native-since: 1.5.0
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##1.5.0##
Serialize and deserialize Java objects using Google's Protocol buffers.
@@ -32,3 +32,32 @@ Please refer to the above link for usage and configuration details.
----
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
+
+== Additional Camel Quarkus configuration
+
+Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
+service and message definitions stored in the `src/main/proto` directory:
+
+[source,xml]
+----
+<build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-code</goal>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+</build>
+----
+
+You may want to check the https://github.com/apache/camel-quarkus/tree/master/integration-tests/protobuf[integration test]
+in our source tree as an example.
+
diff --git a/docs/modules/ROOT/partials/reference/dataformats/protobuf.adoc b/docs/modules/ROOT/partials/reference/dataformats/protobuf.adoc
index d18a245..7910b92 100644
--- a/docs/modules/ROOT/partials/reference/dataformats/protobuf.adoc
+++ b/docs/modules/ROOT/partials/reference/dataformats/protobuf.adoc
@@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-protobuf
:cq-artifact-id-base: protobuf
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.0.0
-:cq-native-since: 1.0.0
+:cq-native-since: 1.5.0
:cq-camel-part-name: protobuf
:cq-camel-part-title: Protobuf
:cq-camel-part-description: Serialize and deserialize Java objects using Google's Protocol buffers.
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index 094e3db..7c524d1 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -111,7 +111,6 @@
<module>openstack</module>
<module>optaplanner</module>
<module>printer</module>
- <module>protobuf</module>
<module>pubnub</module>
<module>pulsar</module>
<module>quickfix</module>
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 5a26abe..4a4e92e 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -167,6 +167,7 @@
<module>pg-replication-slot</module>
<module>pgevent</module>
<module>platform-http</module>
+ <module>protobuf</module>
<module>quartz</module>
<module>qute</module>
<module>rabbitmq</module>
diff --git a/extensions-jvm/protobuf/deployment/pom.xml b/extensions/protobuf/deployment/pom.xml
similarity index 94%
rename from extensions-jvm/protobuf/deployment/pom.xml
rename to extensions/protobuf/deployment/pom.xml
index 9c5f686..4fb6c5b 100644
--- a/extensions-jvm/protobuf/deployment/pom.xml
+++ b/extensions/protobuf/deployment/pom.xml
@@ -38,6 +38,12 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-protobuf</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-grpc-codegen</artifactId>
+ </dependency>
+
</dependencies>
<build>
diff --git a/extensions-jvm/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java b/extensions/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java
similarity index 53%
rename from extensions-jvm/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java
rename to extensions/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java
index 0d0e1ae..ed00faf 100644
--- a/extensions-jvm/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java
+++ b/extensions/protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/protobuf/deployment/ProtobufProcessor.java
@@ -16,31 +16,42 @@
*/
package org.apache.camel.quarkus.component.protobuf.deployment;
+import com.google.protobuf.GeneratedMessage;
+import com.google.protobuf.GeneratedMessageV3;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
class ProtobufProcessor {
private static final Logger LOG = Logger.getLogger(ProtobufProcessor.class);
private static final String FEATURE = "camel-protobuf";
+ private static final DotName[] MESSAGE_CLASS_DOT_NAMES = new DotName[] {
+ DotName.createSimple(GeneratedMessageV3.class.getName()),
+ DotName.createSimple(GeneratedMessage.class.getName())
+ };
@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
- /**
- * Remove this once this extension starts supporting the native mode.
- */
- @BuildStep(onlyIf = NativeBuild.class)
- @Record(value = ExecutionTime.RUNTIME_INIT)
- void warnJvmInNative(JvmOnlyRecorder recorder) {
- JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
- recorder.warnJvmInNative(FEATURE); // warn at runtime
+ @BuildStep
+ void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
+ CombinedIndexBuildItem combinedIndexBuildItem) {
+
+ IndexView index = combinedIndexBuildItem.getIndex();
+ for (DotName dotName : MESSAGE_CLASS_DOT_NAMES) {
+ index.getAllKnownSubclasses(dotName)
+ .stream()
+ .map(classInfo -> new ReflectiveClassBuildItem(true, false, classInfo.name().toString()))
+ .forEach(reflectiveClasses::produce);
+ }
}
+
}
diff --git a/extensions-jvm/protobuf/pom.xml b/extensions/protobuf/pom.xml
similarity index 97%
rename from extensions-jvm/protobuf/pom.xml
rename to extensions/protobuf/pom.xml
index 2380dad..b3f63dd 100644
--- a/extensions-jvm/protobuf/pom.xml
+++ b/extensions/protobuf/pom.xml
@@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/protobuf/runtime/pom.xml b/extensions/protobuf/runtime/pom.xml
similarity index 98%
rename from extensions-jvm/protobuf/runtime/pom.xml
rename to extensions/protobuf/runtime/pom.xml
index df3e512..c7e7b0d 100644
--- a/extensions-jvm/protobuf/runtime/pom.xml
+++ b/extensions/protobuf/runtime/pom.xml
@@ -31,7 +31,7 @@
<properties>
<camel.quarkus.jvmSince>1.0.0</camel.quarkus.jvmSince>
- <camel.quarkus.nativeSince>1.0.0</camel.quarkus.nativeSince>
+ <camel.quarkus.nativeSince>1.5.0</camel.quarkus.nativeSince>
</properties>
<dependencyManagement>
diff --git a/extensions/protobuf/runtime/src/main/doc/configuration.adoc b/extensions/protobuf/runtime/src/main/doc/configuration.adoc
new file mode 100644
index 0000000..9cb9285
--- /dev/null
+++ b/extensions/protobuf/runtime/src/main/doc/configuration.adoc
@@ -0,0 +1,25 @@
+Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
+service and message definitions stored in the `src/main/proto` directory:
+
+[source,xml]
+----
+<build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-code</goal>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+</build>
+----
+
+You may want to check the https://github.com/apache/camel-quarkus/tree/master/integration-tests/protobuf[integration test]
+in our source tree as an example.
diff --git a/extensions-jvm/protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 100%
rename from extensions-jvm/protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 6ed7d39..9f83fb6 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -141,6 +141,7 @@
<module>pgevent</module>
<module>platform-http</module>
<module>platform-http-engine</module>
+ <module>protobuf</module>
<module>quartz</module>
<module>qute</module>
<module>rabbitmq</module>
diff --git a/extensions-jvm/protobuf/integration-test/pom.xml b/integration-tests/protobuf/pom.xml
similarity index 56%
rename from extensions-jvm/protobuf/integration-test/pom.xml
rename to integration-tests/protobuf/pom.xml
index 4051b16..99d5b3a 100644
--- a/extensions-jvm/protobuf/integration-test/pom.xml
+++ b/integration-tests/protobuf/pom.xml
@@ -21,25 +21,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-build-parent-it</artifactId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.5.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>
- <artifactId>camel-quarkus-protobuf-integration-test</artifactId>
- <name>Camel Quarkus :: Protobuf :: Integration Test</name>
+ <artifactId>camel-quarkus-integration-test-protobuf</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: Protobuf</name>
<description>Integration tests for Camel Quarkus Protobuf extension</description>
- <properties>
- <!-- mvnd, a.k.a. Maven Daemon: https://github.com/mvndaemon/mvnd -->
- <!-- The following rule tells mvnd to build the listed deployment modules before this module. -->
- <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not -->
- <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
- <!-- Please update the rule whenever you change the dependencies of this module by running -->
- <!-- mvn process-resources -Pformat from the root directory -->
- <mvnd.builder.rule>camel-quarkus-protobuf-deployment</mvnd.builder.rule>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
@@ -70,36 +59,48 @@
<build>
<plugins>
<plugin>
- <groupId>kr.motd.maven</groupId>
- <artifactId>os-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>initialize</phase>
- <goals>
- <goal>detect</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.xolstice.maven.plugins</groupId>
- <artifactId>protobuf-maven-plugin</artifactId>
- <extensions>true</extensions>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
+ <id>quarkus-generate-code</id>
<goals>
- <goal>compile</goal>
+ <goal>generate-code</goal>
</goals>
<phase>generate-sources</phase>
- <configuration>
- <protocArtifact>
- com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
- </protocArtifact>
- <checkStaleness>true</checkStaleness>
- </configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
similarity index 100%
rename from extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
rename to integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
diff --git a/extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
similarity index 100%
copy from extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
copy to integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
diff --git a/extensions-jvm/protobuf/integration-test/src/main/proto/addressbook.proto b/integration-tests/protobuf/src/main/proto/addressbook.proto
similarity index 100%
rename from extensions-jvm/protobuf/integration-test/src/main/proto/addressbook.proto
rename to integration-tests/protobuf/src/main/proto/addressbook.proto
diff --git a/extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java b/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufIT.java
similarity index 63%
rename from extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
rename to integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufIT.java
index f74d60e..9f84c2a 100644
--- a/extensions-jvm/protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
+++ b/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufIT.java
@@ -16,20 +16,9 @@
*/
package org.apache.camel.quarkus.component.protobuf.it;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person;
+import io.quarkus.test.junit.NativeImageTest;
-public class ProtobufRoute extends RouteBuilder {
+@NativeImageTest
+class ProtobufIT extends ProtobufTest {
- @Override
- public void configure() throws Exception {
- from("direct:protobuf-marshal")
- .marshal()
- .protobuf(Person.class.getName());
-
- from("direct:protobuf-unmarshal")
- .unmarshal()
- .protobuf(Person.class.getName());
-
- }
}
diff --git a/extensions-jvm/protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java b/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
similarity index 100%
rename from extensions-jvm/protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
rename to integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index 3355be6..b60127d 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -26,6 +26,7 @@ cloud:
- consul
- elasticsearch-rest
- grpc
+ - protobuf
- smallrye-reactive-messaging
core-main-validation:
- core