20.2. Avro データ形式の使用

avro データ形式の使用は、ルートでマーシャリングまたはアンマーシャリングするクラスを指定するのと同様に簡単です。

    <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>

別の方法として、コンテキスト内でデータ形式を指定し、ルートから参照することもできます。

    <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 ref="avro"/>
            <to uri="log:out"/>
        </route>
    </camelContext>

同じ方法で、avro データ形式を使用してアンマーシャリングできます。