lundi 3 août 2015

Websockets on auto-scaling Wildfly application on OpenShift

We are building a web application using WildFly and hosted on RedHat OpenShift. We have it set to scale automatically (OpenShift uses HAProxy to load-balance between dynamically created instances).

In this setup, we use Websockets to notify clients about updates. Since the action that creates an update might come in to one app server, and the websocket connection to the client that needs to be updated might be on another web server, notifications currently do not work. We need a way of pooling the server-side Websocket connections, so each instance of the app server can notify any client connected. How can we achieve this?

We create a websocket endpoint like this:

import javax.websocket.server.ServerEndpoint;
import javax.websocket.OnOpen;

@ServerEndpoint("/websocket/browser")
public class w
{
    @onOpen
    public void onOpen(Session session)
    {
        //put the session into a map object with the session ID as a key
    }

}

Then when we want to notify a certain client, we pull the session out of that map and send information to it.

Can we share these Session objects using something like memcached? Or do we need WildFly clustering? Is there something we can use that is provided by OpenShift?

Aucun commentaire:

Enregistrer un commentaire