如果要保留EasyNetQ的消息顺序,是否避免使用异步方法? [英] Do I avoid using Async methods if I want to preserve message order with EasyNetQ?

查看:161
本文介绍了如果要保留EasyNetQ的消息顺序,是否避免使用异步方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在EasynetQ的文档中看到了这一点"

I have seen this in the documentation of EasynetQ"

EasyNetQ为每个IBus实例实现单个使用者线程,因此,如果您使用标准的非异步订阅方法,则消息处理程序将以与RabbitMQ传递消息的顺序同步触发.不需要实现锁.如果您使用异步订阅,则处理程序仍将按顺序调用,但是当然,根据您实现异步处理程序的方式,它们可能会按顺序ACK.

现在,这是否意味着如果要保留消息顺序,我应该避免在订户中使用异步方法(例如httpClient.SendAsync()或方法的任何异步版本)吗?

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?

换句话说,我有message1,message2,我想先处理message1,然后再处理message2.但是,如果我的订户正在使用async/await方法,则message1和message2可能会乱序处理.

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,即使在使用异步时,该时间也可以接收1条消息,但会增加很多mem/cpu开销和性能损失.

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.

这篇关于如果要保留EasyNetQ的消息顺序,是否避免使用异步方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆