3.3. avro 数据格式使用
使用 avro 数据格式与指定您要在路由中 marshal 或 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>
另一种方法是在上下文中指定 dataformat,并从您的路由引用它。
<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。