Questo contenuto non è disponibile nella lingua selezionata.

Chapter 55. Avro


This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro’s binary dataformat. Since Camel 3.2 rpc functionality was moved into separate camel-avro-rpc component.

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

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-avro</artifactId>
    <version>{CamelSBVersion}</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Copy to Clipboard Toggle word wrap

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

55.1. Avro Dataformat Options

The Avro dataformat supports 1 options, which are listed below.

Expand
NameDefaultJava TypeDescription

instanceClassName

 

String

Class name to use for marshal and unmarshalling.

55.2. Avro Data Format usage

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

AvroDataFormat format = new AvroDataFormat(Value.SCHEMA$);

from("direct:in").marshal(format).to("direct:marshal");
from("direct:back").unmarshal(format).to("direct:unmarshal");
Copy to Clipboard Toggle word wrap

Where Value is an Avro Maven Plugin Generated class.

or in XML

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="direct:in"/>
            <marshal>
                <avro instanceClass="org.apache.camel.dataformat.avro.Message"/>
            </marshal>
            <to uri="log:out"/>
        </route>
    </camelContext>
Copy to Clipboard Toggle word wrap

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

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
         <dataFormats>
            <avro id="avro" instanceClass="org.apache.camel.dataformat.avro.Message"/>
        </dataFormats>
        <route>
            <from uri="direct:in"/>
            <marshal><custom ref="avro"/></marshal>
            <to uri="log:out"/>
        </route>
    </camelContext>
Copy to Clipboard Toggle word wrap

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

55.3. Spring Boot Auto-Configuration

When using avro with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-avro-starter</artifactId>
  <version>{CamelSBProjectVersion}</version>
  <!-- Use your Camel Spring Boot version -->
</dependency>
Copy to Clipboard Toggle word wrap

The component supports 2 options, which are listed below.

Expand
NameDescriptionDefaultType

camel.dataformat.avro.enabled

Whether to enable auto configuration of the avro data format. This is enabled by default.

 

Boolean

camel.dataformat.avro.instance-class-name

Class name to use for marshal and unmarshalling.

 

String

Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat