【问题标题】:Spring Integration - asynchronous JMSSpring 集成 - 异步 JMS
【发布时间】:2018-04-18 00:01:10
【问题描述】:

我在以下情况下苦苦挣扎:

WS |============| JMS ~~~异步未来处理~~~

想法如下。传入的 WS 请求存储到 JMS,一旦存储(正确发送),WS 客户端就会以 OK 响应。

我可以通过 spring jmsTemplate 来实现,比如

<chain>
  <service-activator> 
      ... calling jmsTemplate send ...
  </service-activator>
  <OK response>
</chain>

我不想使用 jmsTemplate,但是如果我使用 jms:outbound-channel-adapter,则不会生成回复消息并且它会卡住。其他构造导致同步处理,意味着 WS 响应被延迟,直到 JMS 请求被完全处理。

我相信有一个简单的解决方案,但我花了好几个小时才找到它。谢谢!


编辑: 建议的解决方案有效,非常感谢!我的朋友向我推荐了另一个 - 使用窃听器,恕我直言,它看起来不错。

<int:gateway service-interface="MyService" default-request-channel="in"/>
     <channel id="in">
      <interceptors>
          <wire-tap channel="inJms"/>
      </interceptors>
 </channel>

 <channel id="inJms"/>

 <transformer expression="'OK'" input-channel="in" order="1"/>      

 <jms:outbound-channel-adapter channel="inJms" destination="requestQueue"/>

【问题讨论】:

标签: spring-integration


【解决方案1】:

&lt;publish-subscribe-channel/&gt; 可以帮助您:

<publish-subscribe-channel id="storeMessageChannel"/>

<int-ws:inbound-gateway request-channel="storeMessageChannel"/>   

<int-jms:outbound-channel-adapter channel="storeMessageChannel"/>

<int:transformer input-channel="storeMessageChannel" expression="'OK'"/>

好吧,在这种情况下,来自 WS 的消息将通过两个顺序订阅者发送到 storeMessageChannel: 1. JMS - 将消息放入队列; 2. 简单转换器 - 返回 WS 响应“OK”。

只有在 jms 出站适配器完成工作后,Transformer 才会应用消息。

【讨论】:

  • 非常感谢您的回答,我会深入测试一下。只是为了澄清。为什么转换器仅在适配器完成工作后才应用消息? ow 来实现发送 NOK,例如当JMS 宕机了?非常感谢!
  • 回复。你的最后一个问题:删除这个&lt;channel id="in"/&gt;。实际上(默认情况下)Spring 使用“覆盖”策略,您的频道不是publish-subscribe-channel,而只是direct
猜你喜欢
  • 1970-01-01
  • 2014-08-23
  • 2013-01-06
  • 1970-01-01
  • 2015-11-01
  • 2013-02-04
  • 1970-01-01
  • 2021-11-06
  • 2014-12-20
相关资源
最近更新 更多