Protobuf
JVM since1.0.0 Native since1.5.0
Serialize and deserialize Java objects using Google’s Protocol buffers.
Maven coordinates
Or add the coordinates to your existing project:
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-protobuf</artifactId>
</dependency>
Check the User guide for more information about writing Camel Quarkus applications.
Additional Camel Quarkus configuration
Generate classes from protobuf .proto
files
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:
<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>
The camel-quarkus-protobuf integration test is a good way to learn more.
Serialize/Deserialize Java beans using JSON fields representation
Please note that some additional configurations might be needed when using contentTypeFormat=json
.
Indeed, in such a case, the generated Builder
class needs to be registered for reflection.
For instance, let’s examine the ProtobufDataFormat
below:
ProtobufDataFormat protobufJsonDataFormat = new ProtobufDataFormat(Person.getDefaultInstance(), ProtobufDataFormat.CONTENT_TYPE_FORMAT_JSON);
In such a case, the Person.Builder
class should be registered for reflection, for instance as below:
@RegisterForReflection(targets = { org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person.Builder.class })
A concrete implementation of such a scenario is present in the camel-quarkus-protobuf integration test.