jakarta-eeejbwildflydistributed-computingjava-ee-7

How to distribute an event to all nodes in a (Wildfly) cluster?


I would like to notify all nodes in a cluster when the state of a longer running process in my JavaEE 7 WebApp changes, so that every node can in turn notify their clients via WebSocket about that change.

I am working with Wildfly 10 in a clustered environment.

What JavaEE 7 API / Programming model or Wildfly Service would be todays best practice to achieve that ?


Solution

  • If you want to stay within JavaEE ecosystem, then JMS topic is the way to go. Topics are like broadcast channels - every message listener subscribed to it will get a copy of this message. In wildfly cluster/domain, you need to have JMS enabled(either use full profile or manually add messaging subsystem), then enable clustered messaging and finally create a jms topic, where your notification client will write a message to. You can find a complete example in official wildfly quickstart repo - have a look at helloworld-mdb and messaging-clustering modules.
    You can also use a dedicated PubSub service running outside your java env and let your app create a subscriber to some specific event(e.g. Redis, or Apache camel,..) but messaging in Wildfly is simple and works fine for most use cases.