简体   繁体   English

Spring Integration JMS线程安全

[英]Spring Integration JMS Threadsafe

I'm pretty new to Spring Integration and still trying to get my head around it. 我对Spring Integration还是很陌生,但仍然想尽一切办法。 Right now I'm just trying to understand if the example I've found here is actually safe across multiple threads: 现在,我只是想了解我在这里找到的示例在多个线程中是否真正安全:

https://github.com/spring-projects/spring-integration-samples/blob/master/basic/jms/src/test/java/org/springframework/integration/samples/jms/ChannelAdapterDemoTest.java https://github.com/spring-projects/spring-integration-samples/blob/master/basic/jms/src/test/java/org/springframework/integration/samples/jms/ChannelAdapterDemoTest.java

My use case is as follows: 我的用例如下:

  • Send request to queue with JMS Reply-to as a temporary queue 将请求发送到带有JMS Reply-to的队列作为临时队列
  • Wait for response to be received on the temporary queue 等待在临时队列上收到响应
  • Need this to happen synchronously within a method -- I don't want to split it up and make it asynchronous across several methods 需要在一个方法中同步发生-我不想将其拆分并使其在多个方法之间异步

Will the above example work for this? 上面的示例可以解决这个问题吗? If not, am I barking up the wrong tree? 如果不是,我是不是在树上叫错了?

Thanks in advance. 提前致谢。

That sample is pretty simple; 该示例非常简单。 it just sends the message to stdout so, yes, it's perfectly thread safe. 它只是将消息发送到stdout所以,是的,它是完全线程安全的。

For the request/reply scenario you are talking about, you need to use a <gateway/> - see the other example in that sample project . 对于您正在讨论的请求/答复场景,您需要使用<gateway/> -参见该示例项目中的另一个示例 In that case, you can see that the message is handled by 'demoBean' which, again, is perfectly thread safe. 在这种情况下,您可以看到消息是由'demoBean'处理的,这同样是完全线程安全的。

For a real application, the thread-safetyness depends on the code in the services invoked by the flow receiving the message. 对于实际应用程序,线程安全性取决于接收消息的流所调用的服务中的代码。

If you wish, you can use Spring Integration on the client side too (with an outbound gateway). 如果愿意,您也可以在客户端(通过出站网关)使用Spring Integration。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM