【问题标题】:Missing correlation id in response message with Spring and ActiveMQ使用 Spring 和 ActiveMQ 的响应消息中缺少相关 ID
【发布时间】:2016-12-20 07:58:34
【问题描述】:

我正在通过一个非常简单的实验来学习 Spring Integration。我在 ActiveMQ 中设置了两个队列,即 requestQueue 和 responseQueue。我想要做的是向 requestQueue 发送一条消息,然后应用程序将接收并回显到 responseQueue。这是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" />

还有服务类

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

responseQueue 中的内容进展顺利。问题是相关ID永远不会出现。我希望它将包含请求消息的消息 ID。我试图为入站网关的相关键属性设置不同的值,但没有成功。是有什么问题还是一开始就不应该使用入站网关?

【问题讨论】:

    标签: java activemq spring-integration


    【解决方案1】:

    网关相关处理逻辑是here

    伪代码:

    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`
    

    【讨论】:

    • 还有response-channel是等待网关回复。 JMS 回复(以及相关性)稍后完成
    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 2022-08-02
    • 2016-10-27
    • 1970-01-01
    • 2021-09-02
    • 2015-11-03
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多