Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 321
Thomas Avatar asked Oct 29 '25 18:10

Thomas


1 Answers

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.

like image 161
yntelectual Avatar answered Oct 31 '25 12:10

yntelectual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!