Apache camel ProducerTemplate asyncSendBody设置JMS头和属性

时间:2016-01-29 02:29:04

标签: apache-camel jms spring-jms

Apache camel api有ProducerTemplate.asyncSendBody(Endpoint endpoint, Object body)。 我使用上面的方法将消息发送到远程端点。

我想知道如何设置其他JMS属性和标题。

我看到有一个api sendBodyAndHeader()允许这样做。在async api中它的等价物是什么?

1 个答案:

答案 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());
}