【问题标题】:Apache camel ProducerTemplate asyncSendBody set JMS headers and propertiesApache camel ProducerTemplate asyncSendBody 设置 JMS 标头和属性
【发布时间】:2016-01-29 02:29:04
【问题描述】:

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

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

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

【问题讨论】:

    标签: apache-camel jms spring-jms


    【解决方案1】:

    您可以使用asyncRequestBodyAndHeader 方法异步发送Camel Exchange。骆驼交换将发送至Exchange.InOut MEP。

    这是一个你可以遵循的测试用例,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多