Rechercher

Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 3. Avro

download PDF

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.

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

3.1. Dependencies

When using camel-avro with Red Hat build of Camel Spring Boot, add the following Maven dependency to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-avro-starter</artifactId>
</dependency>

3.2. Avro Dataformat Options

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

NameDefaultJava TypeDescription

instanceClassName

 

String

Class name to use for marshal and unmarshalling.

3.3. 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");

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>

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>

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

3.4. Spring Boot Auto-Configuration

When using avro with Spring Boot make sure to add the Maven dependency to have support for auto configuration. The component supports 2 options, which are listed below.

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

Red Hat logoGithubRedditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez leBlog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

© 2024 Red Hat, Inc.