An EventBus
is good for decoupling parts of the system, so that the producers only knows the EventBus
and the consumers knows it indirectly by means of @Subscribe
(some code must know both the consumer and the EventBus
, so it can call register
).
You may or may not need such decoupling. The EventBus
may deliver events synchronously on the same thread (the default) or using a provided Executor
. If you don't want the producers to be slowed down by the subscribers, then you can use the asynchronous version.
If you want that the producers don't get slowed down, then you may use some BlockingQueue
from java.util.concurrent
. Look at LinkedBlockingQueue
and ArrayBlockingQueue
, if you want to apply backpressure (i.e., to slow down the produces if the queue grows big).
If you don't care that both producers and consumers must see your queue, then you don't need an EventBus
. If you do, then you can use it e.g., so that the producers post an event subscribed by a thread filling the queue. Or there may be a thread polling the queue and posting to the bus.
Or both, but don't over-engineer it, just KISS.
AFAICT, proper message queue is an overkill when working inside of a single Java process.
You should add more details to get a recommendation.