Avro Component

Available as of Camel 2.10

This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro's binary dataformat. Moreover, it provides support for Apache Avro's rpc, by providing producers and consumers endpoint for using avro over netty or http.

Maven users will need to add the following dependency to their pom.xml for this component:

Apache Avro Overview

Avro allows you to define message types and a protocol using a json like format and then generate java code for the specified types and messages. An example of how a schema looks like is below.

You can easily generate classes from a schema, using maven, ant etc. More details can be found at the Apache Avro documentation.

However, it doesn't enforce a schema first approach and you can create schema for your existing classes. Since 2.12 you can use existing protocol interfaces to make RCP calls. You should use interface for the protocol itself and POJO beans or primitive/String classes for parameter and result types. Here is an example of the class that corresponds to schema above:

Note: Existing classes can be used only for RPC (see below), not in data format.

Using the Avro data format

Using the avro data format is as easy as specifying that the class that you want to marshal or unmarshal in your route.

An alternative can be to specify the dataformat inside the context and reference it from your route.

In the same manner you can umarshal using the avro data format.

Using Avro RPC in Camel

As mentioned above Avro also provides RPC support over multiple transports such as http and netty. Camel provides consumers and producers for these two transports.

The supported transport values are currently http or netty.

Since 2.12 you can specify message name right in the URI:

For consumers this allows you to have multiple routes attached to the same socket. Dispatching to correct route will be done by the avro component automatically. Route with no messageName specified (if any) will be used as default.

When using camel producers for avro ipc, the "in" message body needs to contain the parameters of the operation specified in the avro protocol. The response will be added in the body of the "out" message.

In a similar manner when using camel avro consumers for avro ipc, the requests parameters will be placed inside the "in" message body of the created exchange and once the exchange is processed the body of the "out" message will be send as a response.

Note: By default consumer parameters are wrapped into array. If you've got only one parameter, since 2.12 you can use singleParameter URI option to receive it direcly in the "in" message body without array wrapping.

Avro RPC URI Options






The class name of the avro protocol.



If true, consumer parameter won't be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message



Avro procol object. Can be used instead of protocolClassName when complex protocol needs to be created. One cane used #name notation to refer beans from the Registry



If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be autodetected

Avro RPC Headers




The name of the message to send. In consumer overrides message name from URI (if any)


An example of using camel avro producers via http:

In the example above you need to fill CamelAvroMessageName header. Since 2.12 you can use following syntax to call constant messages:

An example of consuming messages using camel avro consumers via netty:

Since 2.12 you can set up two distinct routes to perform the same task:

In the example above, get takes only one parameter, so singleParameter is used and getProcessor will receive Value class directly in body, while putProcessor will receive an array of size 2 with String key and Value value filled as array contents.

© 2004-2014 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram