266.7. Java DSL
您可以使用创建 ProtobufDataFormat 实例,并将其传递给 Camel DataFormat marshal 和 unmarshal API,如下所示:
ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());
from("direct:in").marshal(format);
from("direct:back").unmarshal(format).to("mock:reverse");
或者,使用 DSL protobuf ()传递 unmarshal 默认实例或默认实例类名称,如下所示。
// 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");