我正在通过一个非常简单的实验学习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。我试图将不同的值赋予inbound-gateway的correlation-key属性,但没有成功。是否有问题或者首先不应该使用入站网关?
答案 0 :(得分:0)
Tha gateway correlation handling logic is here.
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`