37.6. 默认有效负载类型
默认情况下,Camel Paho 组件在提取的二进制有效负载上运行(或放入)信息:
// Receive payload byte[] payload = (byte[]) consumerTemplate.receiveBody("paho:topic"); // Send payload byte[] payload = "message".getBytes(); producerTemplate.sendBody("paho:topic", payload);
但是,Camel 内置 类型转换 API 可以为您执行自动数据类型转换。在以下示例中,Camel 将二进制有效负载自动转换为 字符串
(并解释):
// Receive payload String payload = consumerTemplate.receiveBody("paho:topic", String.class); // Send payload String payload = "message"; producerTemplate.sendBody("paho:topic", payload);