使用 Guava 的 EventBus 的注意事项
Caveats for using Guava's EventBus
来自docs
It is not a general-purpose publish-subscribe system, nor is it intended for interprocess communication
他们说它不是通用的发布-订阅系统是什么意思?
据我了解,这仅在 JVM 内,publish/subscribe 通常在驻留在可能不同位置的进程之间:就像一个 JVM 与另一个 JVM 对话一样,假设一个 Spring 应用程序发布事件将由位于完全不同位置的另一个 Spring 应用程序使用。
最好在the EventBusExplained page的底部解释:
Why can't I do <magic thing> with EventBus?
EventBus is designed to
deal with a large class of use cases really, really well. We prefer
hitting the nail on the head for most use cases to doing decently on
all use cases.
Additionally, making EventBus extensible -- and making it useful and
productive to extend, while still allowing ourselves to make additions
to the core EventBus API that don't conflict with any of your
extensions -- is an extremely difficult problem.
If you really, really need magic thing X, that EventBus can't
currently provide, you should file an issue, and then design your own
alternative.
(强调我的。)
例如,将 EventBus 与 Kafka 进行比较——后者的可扩展性更高,但也更复杂。
来自docs
It is not a general-purpose publish-subscribe system, nor is it intended for interprocess communication
他们说它不是通用的发布-订阅系统是什么意思?
据我了解,这仅在 JVM 内,publish/subscribe 通常在驻留在可能不同位置的进程之间:就像一个 JVM 与另一个 JVM 对话一样,假设一个 Spring 应用程序发布事件将由位于完全不同位置的另一个 Spring 应用程序使用。
最好在the EventBusExplained page的底部解释:
Why can't I do <magic thing> with EventBus?
EventBus is designed to deal with a large class of use cases really, really well. We prefer hitting the nail on the head for most use cases to doing decently on all use cases.
Additionally, making EventBus extensible -- and making it useful and productive to extend, while still allowing ourselves to make additions to the core EventBus API that don't conflict with any of your extensions -- is an extremely difficult problem.
If you really, really need magic thing X, that EventBus can't currently provide, you should file an issue, and then design your own alternative.
(强调我的。)
例如,将 EventBus 与 Kafka 进行比较——后者的可扩展性更高,但也更复杂。