简体   繁体   English

使用Spring和ActiveMQ在响应消息中缺少相关ID

[英]Missing correlation id in response message with Spring and ActiveMQ

I am learning Spring Integration with a very simple experiment. 我正在通过一个非常简单的实验学习Spring Integration。 I have setup two queues in ActiveMQ, namely requestQueue and responseQueue. 我在ActiveMQ中设置了两个队列,即requestQueue和responseQueue。 What I want to do is that a message is sent to the requestQueue and then the application will pick up and echo back to the responseQueue. 我想要做的是将一条消息发送到requestQueue,然后应用程序将拾取并回显给responseQueue。 Here is the configuration in integration.xml 这是integration.xml中的配置

<int:channel id="requestChannel"/>
<int:channel id="responseChannel"/>
<int:service-activator id="echoServiceActivator" input-channel="requestChannel" ref="echoServiceImpl"
                       requires-reply="true" output-channel="responseChannel"/>

<jms:inbound-gateway request-channel="requestChannel" reply-channel="responseChannel"
                     connection-factory="jmsConnectionFactory"
                     request-destination="requestQueue" default-reply-destination="responseQueue"
                     id="echoGateway" />

And the service class 和服务类

@Service
public class EchoServiceImpl implements EchoService {

  private static final Logger logger = LoggerFactory.getLogger(EchoServiceImpl.class);

  @Override
  @ServiceActivator
  public String echo(Message<String> message) {
    logger.info("Received message: {}", message.getPayload());
    return message.getPayload();
  }
}

Things go well with the content in the responseQueue. 事情与responseQueue中的内容相吻合。 The problem is that the correlation-id never shows up. 问题是,相关性ID永远不会出现。 I expect that it will contain the message id of the request message. 我希望它将包含请求消息的消息ID。 I have tried to put different value to correlation-key attribute of inbound-gateway but to no success. 我试图将不同的值赋予inbound-gateway的correlation-key属性,但没有成功。 Is there something wrong or the inbound-gateway should not be used at the first place? 是否有问题或者首先不应该使用入站网关?

Tha gateway correlation handling logic is here . Tha网关关联处理逻辑就在这里

Pseudo code: 伪代码:

If the gateway has a `correlation-key`
    if the correlation key is `JMSCorrelationID`
        echo the inbound `message.JMSCorrelationID`
    else
        echo the inbound correlation key header
else
    if the inbound message has a `JMSCorrelationID`
        echo the inbound `message.JMSCorrelationID`
    else
        set the `reply.JMSCorrelationID` to the inbound `message.JMSMessageID`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM