I am adding a WebSocket handler to my Azure Webapp. Lets say that I am writing chat server (though I'm not), where the server will keep a list of all open connections in memory so that all connected clients can talk to each other.
Now, I have auto-scaling turned on so my server can some point in time scale out to 2 instances. Now clients connected to instance 1 cannot talk to clients who happen to be connected to instance 2.
To solve this I am trying to find out if it is possible to target a specific instance using Azures ARRAffinity cookie, but what I found so far, this is only possible:
- For ordinary web requests (not "new WebSocket()")
- From server to server using node.js
So my question, is it in fact possible in some way to this with websockets? Do you have some other suggestions?
EDIT 2017-11-02: This is still an interesting question, but I have solved it in a different (mostly positive) way: Since all messages going through the websocket is already serialized, it was easy to utilize my already present Redis cache publish/subscribe functionality.
So what I do now is:
- Message comes through websocket from client A - targeted at client B.
- Message arrives at webserver X (one of many possible webservers depending on scale out)
- Message is published to a Redis cache channel
- All webservers subscribes to Redis cache channel and receives the message
- The one webserver who happens to hold a websocket connection to the target client delivers the message, all other webservers ignore the message