Search code examples
javarmiguava

Subscribe to EventBus on RMI host


Do EventBus events work across an RMI connection?

Basic idea: I have an RMI server and any number of clients. The server holds the EventBus object and publishes it via a getEventBus() method.

Desired outcome: When a client publishes something on the server's EventBus, other registered clients are informed.

Has anyone done something like this or knows why it wouldn't work? Are there any pitfalls if it does?


Solution

  • Messages published by EventBus are only avaiable within your JVM. Since you use RMI I guess your server/clients will run in their own environments, so this is not possible (eventhough I heard, that ppl tried to implement a remote EventBus, but I don't know if that succeded). Normally EventBus is used for UI specific communication within the same application.

    As soon as you want to communicate between different JVMs, something like Java Messaging Services (JMS) comes in handy to broadcast Events from server to interested clients. A famous implementation of JMS is ActiveMQ.