简体   繁体   中英

clustering a spring web application using JMS or Redis

This might be a stupid question but please hold the gun because I have done a lot of research but this one point just doesn't click in my head.

Let's say I have a spring mvc web application and users can subscribe to it using websockets or any other mechanism ... We get a connection object be it a HttpSession, DeferredResult, AtmosphereResource etc and then we make a local map and store this suspended connection ... Now when we need to send updates we just pick it up from the in memory map and send updates.

Now, what if I have a cluster of tomcats and the user can connect to any node how do they share these suspended connections ? It is not a session replication problem I dont store anything in the session I just need to have a way to connect back to the client...

If that's a wrong way of thinking then how do I make a clustered environment work ? The user connects to any node and what happens when that node goes down?

Any help is very much appreciated I'm very desperate for this because our project is stuck at a critical phase.

It looks like you're trying to solve many problems at once:

  • how to manage websocket connections in a clustered environment?
  • how to manage heartbeats, (dis)connections events on the server side?
  • how to manage heartbeats, (dis)connections events on the client side?
  • how to efficiently drive your messaging-driven application with Spring?
  • and more...

Spring 4 introduced websocket support with very cool features that answer a lot of your problems. In a clustered environment, Spring is recommending a MQ instance (that supports STOMP) such as RabbitMQ. This MQ will manage topic subscriptions and messages distribution, while each tomcat will manage client connections.

There are a couple of example applications that show how this works: a portfolio app and a chat app .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM