有一个请求队列和应答队列由客户端服务器实例创建并固定到每个实例,而不是使用临时队列。
用例需要获取入站jms消息,然后将该消息发送到异步流程。从服务接收到异步回复消息后,我需要获取这些结果并回复到原始消息的jmsReplyTo。Jms网关在此实例中无法工作AFAIK>
我使用jms消息驱动的通道适配器来处理消息传入,并使用一系列通道和服务激活器来处理进程外调用和异步应答。我试图使用DynamicDestinationResolver无济于事。此外,我曾尝试以编程方式设置出站目的地地址,但无法找出一个好方法来做到这一点。
这似乎是一个常见的模式,但我找不到一个完全断开连接的异步请求响应的好例子。断开连接意味着通常的异步jms请求回复似乎不适合需要。
环境配置:
<!-- Input from Amq -->
<amq:queue id="requestQueue" physicalName="${request.queue}" />
<int-jms:message-driven-channel-adapter id="jmsIn"
connection-factory="jmsConnectionFactory"
destination="requestQueue"
channel="queueRequestChannel" concurrent-consumers="5" />
<int:channel id="queueRequestChannel" />
<int:service-activator input-channel="queueRequestChannel" ref="switchMessageHandler" method="processSwitchMessage"
output-channel="cardNetworkOutChannel"/>
<!-- Output to Card Network-->
<int:channel id="cardNetworkOutChannel" />
<!--<int:service-activator input-channel="cardNetworkOutChannel" ref="cardNetworkHandler" method="send8583Message" />-->
<!-- Simply used to mock the card network by transforming a SwithMessage to a SwitchMessageResponse * Not needed for target solution -->
<int:transformer id="requestResponseTransformer" ref="nettyCardNetworkClientMock" input-channel="cardNetworkOutChannel"
method="process" output-channel="cardNetworkInChannel"/>
<!-- Input from Card Network -->
<int:channel id="cardNetworkInChannel" />
<int:service-activator input-channel="cardNetworkInChannel" ref="switchMessageHandler" method="sendSwitchMessage"
output-channel="queueReplyChannel"/>
<int:channel id="queueReplyChannel"/>
<int-jms:outbound-channel-adapter
destination-resolver="simpleDestinationResolver" connection-factory="jmsConnectionFactory"
channel="queueReplyChannel" destination-expression="headers.jms_replyTo" />
我刚刚更新了jms示例应用程序,使服务器端使用独立的适配器而不是入站网关,它工作得很好…
<!-- <jms:inbound-gateway id="jmsin" -->
<!-- request-destination="requestQueue" -->
<!-- request-channel="demoChannel"/> -->
<channel id="demoChannel"/>
<jms:message-driven-channel-adapter destination="requestQueue" channel="demoChannel" />
<service-activator input-channel="demoChannel" ref="demoBean" output-channel="reply" />
<channel id="reply" />
<jms:outbound-channel-adapter channel="reply" destination-expression="headers['jms_replyTo']" />
打开DEBUG日志-我们输出了很多有用的东西。
编辑
我只是把它变成异步的…
<channel id="reply">
<queue/>
</channel>
<jms:outbound-channel-adapter channel="reply" destination-expression="headers['jms_replyTo']">
<poller fixed-delay="3000"/>
</jms:outbound-channel-adapter>
EDIT2
根据您在客户端使用的内容,许多客户端需要将入站消息id用作关联id。(默认情况下,出站网关是这样,具有命名的应答队列,除非您提供correlation-key
)。
所以,要设置correlationId,你可以使用header富集器;我刚刚测试了这个…
<chain input-channel="reply">
<header-enricher>
<header name="jms_correlationId" expression="headers['jms_messageId']" />
</header-enricher>
<jms:outbound-channel-adapter destination-expression="headers['jms_replyTo']"/>
<poller fixed-delay="1000" />
</chain>