58.2. Avro 数据格式使用
使用 avro 数据格式非常简单,就像指定您希望在路由中总结或 unmarshal 的类一样容易。
AvroDataFormat format = new AvroDataFormat(Value.SCHEMA$);
from("direct:in").marshal(format).to("direct:marshal");
from("direct:back").unmarshal(format).to("direct:unmarshal");
其中 Value 是一个 Avro Maven 插件生成的类。
或在 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>
另一种方法是指定上下文内的数据格式,并从您的路由引用它。
<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>
同样,您可以使用 avro 数据格式进行 umarshal。