【问题标题】:Spring Integration jms aysnchronous request/replySpring Integration jms aysnchronous request/reply
【发布时间】:2015-05-06 01:26:47
【问题描述】:

我们需要使用 SI 服务为 GUI 提供服务。 GUI 通过 JMS 队列与后端通信,并将等待 jms replyTo 标头属性中指定的 tmp 队列上的响应。

因此可以有 10 个 gui 向后端进行查询,并在各自的 tmp 队列上接收消息。

所以我使用入站网关编写了一个 SI 服务,看起来像这样

<int:channel id="inChannel" />  
<int:channel id="outChannel" />

<int-jms:inbound-gateway id="jmsSampleService" request-destination-name="TEST_QUEUE_2" request-channel="inChannel" 
connection-factory="qpidJmsConnectionFactory" extract-request-payload="true" error-channel="errorChannel" /> 
<int:service-activator input-channel="inChannel" ref="sampleService2" method="processMessage" />

public class SampleService2 {

public Response processMessage(Object obj) throws Exception {
    LOG.info("Message received on sample service. ");
    Thread.sleep(5000);     
    Response response = new ResponseImpl();
    response.setPayload("Test response");
    return response;
}

这很好用,我可以看到服务在 jmsReplyTo 队列上返回一条消息。但是,这是一个单线程同步操作,这意味着除非 GUI1 得到服务,否则 GUI2 的调用将被阻止。我想异步执行此操作,因为这只是对类的方法调用。

我们在 mule 中做了类似的事情

<flow name="sampleServiceFlow">
  <jms:inbound-endpoint queue="TEST_QUEUE" connector-ref="queryQpidConnector" />                    
  <byte-array-to-object-transformer />
  <component>
      <spring-object bean="sampleService" />
  </component>
  <object-to-byte-array-transformer />
  <expression-filter evaluator="groovy"
        expression="message.getOutboundProperty('replyToQueueName') != null" />
  <jms:outbound-endpoint queue="#[header:OUTBOUND:replyToQueueName]" connector-ref="queryQpidConnector" />             
</flow>

由于 mule 服务没有任何 txns,它可以简单地在 auto-ack 中消费一条消息,并让 SampleService 的方法调用为调用服务。

有没有办法在 SI 中实现类似的东西?也许通过使用消息驱动通道适配器?有没有办法在通道之间传播 jms 标头属性?

【问题讨论】:

    标签: asynchronous jms spring-integration


    【解决方案1】:

    只需在入站网关上使用并发。 concurrent-consumers 是最小值 max-concurrent-consumers(如果指定)是最大值;适配器的容器,根据需求调整并发。

    我不确定你的意思

    有没有办法在通道之间传播 jms 标头属性?

    jms 标头映射到集成标头,反之亦然。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 2017-06-24
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多