Do I avoid using Async methods if I want to preserve message order with EasyNetQ?

馋奶兔 提交于 2019-12-11 18:48:49

问题


I have seen this in the documentation of EasynetQ"

EasyNetQ implements a single consumer thread per IBus instance, so if you use the standard non-async subscribe method your message handler will fire synchronously in the same order that messages are delivered by RabbitMQ. There shouldn't be any need to implement a lock. If you use the async subscribe, the handlers will still be called in order, but of course they may ACK out of order depending on how you implement your async handler.

Now, does this mean I should avoid using async methods (like httpClient.SendAsync() or any async versions of methods) in my subscriber if I want to preserve message order?

In other words I have message1, message2, I want to process message1 and then message2. But if my subscriber is using async/await methods then message1 and message2 can be processed out of order.


回答1:


You are correct. Additionally you can set the prefetch count to 1, which picks up 1 message at the time even when using async, but adds a lot of mem/cpu overhead and a performance penalty.

Generally I would recommend to design your application not to be dependent on message order, because it will hurt your scalability in many ways. And it will probably come back to bite you in other ways.



来源:https://stackoverflow.com/questions/54504464/do-i-avoid-using-async-methods-if-i-want-to-preserve-message-order-with-easynetq

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