Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository: https://github.com/apache/camel/blob/master/README.md https://github.com/apache/camel/blob/master/components/readme.adoc
Protobuf - Protocol Buffers
"Protocol Buffers - Google's data interchange format"
Available from Camel 2.2
Camel provides a Data Format to serialse between Java and the Protocol Buffer protocol. The project's site details why you may wish to choose this format over xml. Protocol Buffer is language-neutral and platform-neutral, so messages produced by your Camel routes may be consumed by other language implementations.
This quick overview of how to use Protobuf. For more detail see the complete tutorial
Defining the proto format
The first step is to define the format for the body of your exchange. This is defined in a .proto file as so:
Generating Java classes
The Protobuf SDK provides a compiler which will generate the Java classes for the format we defined in our .proto file. You can run the compiler for any additional supported languages you require.
This will generate a single Java class named AddressBookProtos which contains inner classes for Person and AddressBook. Builders are also implemented for you. The generated classes implement com.google.protobuf.Message which is required by the serialisation mechanism. For this reason it important that only these classes are used in the body of your exchanges. Camel will throw an exception on route creation if you attempt to tell the Data Format to use a class that does not implement com.google.protobuf.Message. Use the generated builders to translate the data from any of your existing domain classes.
You can use create the ProtobufDataFormat instance and pass it to Camel DataFormat marshal and unmarsha API like this.
Or use the DSL protobuf() passing the unmarshal default instance or default instance class name like this.
The following example shows how to use Castor to unmarshal using Spring configuring the protobuf data type
To use Protobuf in your camel routes you need to add the a dependency on camel-protobuf which implements this data format.
If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).