265.7. Java DSL

ProtobufDataFormat インスタンスを作成して、このように Camel DataFormat マーシャルおよびアンマーシャル API に渡すことができます。

   ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());

   from("direct:in").marshal(format);
   from("direct:back").unmarshal(format).to("mock:reverse");

または、非整列化デフォルトインスタンスまたはデフォルトインスタンスクラス名を次のように渡す DSL protobuf() を使用します。

   // You don't need to specify the default instance for protobuf marshaling
   from("direct:marshal").marshal().protobuf();
   from("direct:unmarshalA").unmarshal()
       .protobuf("org.apache.camel.dataformat.protobuf.generated.AddressBookProtos$Person")
       .to("mock:reverse");

   from("direct:unmarshalB").unmarshal().protobuf(Person.getDefaultInstance()).to("mock:reverse");