4

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 ?

Thomas
  • 620
  • 7
  • 19

2 Answers2

5

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.

yntelectual
  • 3,028
  • 18
  • 24
0

There is another way invented by Eder Ignatowicz from Red Hat. He extended the CDI event mechanism to a clustered environment, making it easy and almost transparent to fire an event on one node and observe it on another node. You can read about it here: https://medium.com/kie-foundation/transparent-cdi-events-distribution-in-a-cluster-environment-via-metaprogramming-4c57914df0d6

The algorithm is as follows:

  1. Observe all CDI events and check if a CDI event object type has the @Clustered annotation.
  2. If it has, serialize it and sent a serialized cluster message with the event data (still using JMS as the carrier).
  3. In each other node, receive the event, deserialize it and fire as a regular CDI event.

Here's the algorithm diagram:

enter image description here

mrts
  • 16,697
  • 8
  • 89
  • 72