Spring AMQP ensuring message order in multi-threaded environment

筅森魡賤 提交于 2019-12-25 03:36:05

问题


RabbitMQ guarantees message order if the same Publish Channel->Exchange->Queue->Receive Channel is used. It appears Spring AMQP allows me to guarantee all those pieces except for the publish channel. This is causing messages to get out of order. Below is the problem case:

1.) I have a single thread publishing messages in order on a single exchange 2.) I have a collection of other threads publishing messages on different exchanges and sometimes creating new consumers for different exchanges

Using the cached connection factory it has a cache of channels. Each time a publish is made it goes to the cache to get a channel. Because other threads are publishing and consuming there are no guarantees that the same channel will be used for successive publishes by my main thread. This is true even if I have a cache of one. Has anybody gotten around this issue?

Ideally I would like a dedicated channel for a publisher-exchange combination or at the very least a dedicated channel for publishing. I don't see a way of providing either. It seems a significant flaw in the Spring AMQP if there is no way to guarantee publish order when RabbitMQ has a mechanism for guaranteeing order.


回答1:


You would have to use a dedicated connection (hence: connection factory) for each publisher.

Or, you could use RabbitTemplate.execute() and use the channel provided in the callback to publish al messages.



来源:https://stackoverflow.com/questions/26242254/spring-amqp-ensuring-message-order-in-multi-threaded-environment

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