Apache camel api有ProducerTemplate.asyncSendBody(Endpoint endpoint, Object body)
。
我使用上面的方法将消息发送到远程端点。
我想知道如何设置其他JMS属性和标题。
我看到有一个api sendBodyAndHeader()允许这样做。在async api中它的等价物是什么?
答案 0 :(得分:0)
您可以使用asyncRequestBodyAndHeader
方法异步发送Camel Exchange。骆驼交换将在Exchange.InOut
环境保护部发送。
这是您可以关注的测试案例,
protected Object expectedBody = "<time>" + new Date() + "";
protected ActiveMQQueue replyQueue = new ActiveMQQueue("test.reply.queue");
protected String correlationID = "ABC-123";
protected String messageType = getClass().getName();
public void testForwardingAMessageAcrossJMSKeepingCustomJMSHeaders() throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedBodiesReceived(expectedBody);
AssertionClause firstMessageExpectations = resultEndpoint.message(0);
firstMessageExpectations.header("cheese").isEqualTo(123); firstMessageExpectations.header("JMSReplyTo").isEqualTo(replyQueue);
firstMessageExpectations.header("JMSCorrelationID").isEqualTo(correlationID);
firstMessageExpectations.header("JMSType").isEqualTo(messageType);
template.asyncRequestBodyAndHeader("activemq:test.a", expectedBody, "cheese", 123);
resultEndpoint.assertIsSatisfied();
List<Exchange> list = resultEndpoint.getReceivedExchanges();
Exchange exchange = list.get(0);
Object replyTo = exchange.getIn().getHeader("JMSReplyTo");
LOG.info("Reply to is: " + replyTo);
Destination destination = assertIsInstanceOf(Destination.class, replyTo);
assertEquals("ReplyTo", replyQueue.toString(), destination.toString());
}