2016-08-13 35 views
1

我正在通過一個非常簡單的實驗來學習Spring Integration。我在ActiveMQ中設置了兩個隊列,分別是requestQueue和responseQueue。我想要做的是將一條消息發送到requestQueue,然後應用程序將拾取並回顯到responseQueue。這裏是integration.xmlSpring和ActiveMQ在響應消息中缺少關聯ID

<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。我試圖給入站網關的關聯關鍵屬性賦予不同的價值,但沒有成功。有沒有問題或入境網關不應該在第一個地方使用?

回答

0

Tha網關關聯處理邏輯是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` 
+0

另外'響應channel'爲等待答覆爲網關。 JMS回覆(因此相關)稍後完成 –

相關問題