Wildfly - Communication between 2 Websockets on separate nodes?

cluster-computing, jakarta-ee, jboss, websocket, wildfly

Solution

You can do this in two ways

1) You can create a separate push service on different web server, make publisher and subscriber listen to this service. Use this push service as broker, that is whenever publisher is ready with the data to push they will push it to this service then the broker gets the data broadcasts to all the subscribers.

2) You can create a JMS queue on a seperate JVM, make publisher and subscriber listen to this service. Use this JVM service as broker.

You can also use this service for other purposes also like securing the messages, maintaining sessions, store messages for future delivery when intended receiver is not available to receive the messages.

However the disadvantage of using the model is it will add one more maintenance overhead to your application setup.

Problem

We are developing an application that will include some rudimentary chat/message passing functionality. The web application is deployed on Wildfly 8.x, and makes use of standard JavaEE 7 libraries (as opposed to an additional application framework like Spring) We're leveraging Websockets to accomplish this, as we need the push-to-browser functionality it provides. However, we're deploying this web application in a clustered/HA configuration. If UserA is connected to NodeA and passes in a message that is destined to UserB connected to NodeB, how do we do the transport of this message? In a single-node configuration, the simple answer would be to maintain a static `Map` or `List` that has all of the Websockets and sessions, and route to the appropriate Websocket based on the message destination. But, with more than one node that obviously won't work because the static `Map`/`List` is per-JVM. How would we go about accomplishing this goal? Would it be possible to use JMS and have each Websocket act as a JMS listener? What impact would this have on resource utilization or scalability and performance? We're at a bit of a loss as to how to solve this problem, and would really appreciate any advice you can give.

Original source