简体   繁体   English

使用http-outbound-gateway的请求-回复模式的通道

[英]Channels for request-reply pattern using http-outbound-gateway

I need to send request and receive response synchronously (in the same thread) using http-outbound-gateway in multi-threaded environment (multiple threads doing the same). 我需要在多线程环境(多个线程执行相同操作)中使用http-outbound-gateway同步发送请求和接收响应(在同一线程中)。

I am thinking to use DirectChannel as request and response channels in http-outbound-gateway. 我正在考虑将DirectChannel用作http-outbound-gateway中的请求和响应通道。 If I do that, will the following scenario occurs: 如果我这样做,会发生以下情况:

  1. thread1 pushed request1 into channel 线程1将request1推入通道
  2. thread1 subscribed for response using subscriber1 with context of request1 线程1使用带请求1上下文的订户1订阅了响应
  3. thread2 pushed resquest2 into channel 线程2将resquest2推入通道
  4. thread2 subscribed for response using subsciber2 with context of request2 线程2使用带请求2上下文的subsciber2订阅了响应
  5. response2 received and processed by thread2 using subscriber1 with context of request1 线程2使用subscriber1和request1上下文接收和处理response2

Note: The request/response channels are same for both the threads. 注意:两个线程的请求/响应通道相同。

If this occurs how to resolve this problem. 如果发生这种情况,如何解决此问题。 My requirement is, always the thread that generated the request should process the corresponding response. 我的要求是,生成请求的线程始终应处理相应的响应。

No; 没有; it's completely thread safe; 它是完全线程安全的; thread1 will get its response; thread1将得到其响应; thread2 will get its response; thread2将得到其响应; there can be no cross-talk. 不能有串扰。

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

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