简体   繁体   English

Guava EventBus - FIFO 还是 LIFO?

[英]Guava EventBus - FIFO or LIFO?

This is a very generic question on EventBus.这是一个关于 EventBus 的非常通用的问题。 Does the EventBus exhibit a FIFO or LIFO behavior? EventBus 是否表现出 FIFO 或 LIFO 行为? I am using the EventBus as a Java event "queuing" mechanism and seeing LIFO behavior when a single publisher publishes events to the EventBus faster than the Subscriber can handle.我将 EventBus 用作 Java 事件“排队”机制,并在单个发布者向 EventBus 发布事件的速度比订阅者可以处理的速度快时看到 LIFO 行为。

EventBus doc says that the messages will be sent to all handlers, but there is nothing about their order. EventBus 文档说消息将发送到所有处理程序,但没有关于它们的顺序。 So I would not bet that the specific order is preserved.所以我不会打赌保留了特定的顺序。 Even if now order is preserved without explicit information in the documentation, this may change in the future, so you shouldn't rely on these suspicions.即使现在在文档中没有明确信息的情况下保留了订单,这在未来可能会发生变化,因此您不应该依赖这些怀疑。

In particular, if you use an asynchronous implementation, then surely you don't have warranty of order.特别是,如果您使用异步实现,那么您肯定没有订单保证。

If you need to send some messages and keep their order, you can use other solutions which ordering guarantees like Apache Kafka .如果您需要发送一些消息并保持它们的顺序,您可以使用其他具有顺序保证的解决方案,例如Apache Kafka

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

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