Spring Integration - Parallel ordered processing

雨燕双飞 提交于 2019-12-14 03:02:23

问题


In the application i work on, there is a continuous flow of messages coming from a TCP socket. Messages have different types. Different types of messages should be processed in parallel. But each specific type of message must be processed in the order they come in. I used ExecutorChannel from spring integration and it solves parallel processing need. I created a channel for each specific type of message. But i cannot guarantee ordered processing of messages for specific types.

Is there a way to do ordered processing with publish/subscribe channels while also using parallel processing?


回答1:


Consider to use the same ExecutorChannel but as an input for each type. The trick that each of them should be configured with executors with a single thread. So, you have as much single-threaded executor channels as you have message types.

Another trick is like QueueChannel for each type and polling endpoints with the fixed-delay as subscribers to those queues.

One more option available since the current Spring Integration 5.0 is FluxMessageChannel. The ordering is guaranteed by the internal Reactor's Flux and the parallelism will be achieved by the subscribers - the processing messages in Flux is happened in the subscriber thread.



来源:https://stackoverflow.com/questions/47131088/spring-integration-parallel-ordered-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!