简体   繁体   English

使用JMS或Redis集群Spring Web应用程序

[英]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. 假设我有一个spring mvc Web应用程序,并且用户可以使用websockets或任何其他机制来订阅它……我们得到一个连接对象,例如HttpSession,DeferredResult,AtmosphereResource等,然后我们制作一个本地地图并存储此暂停的连接...现在,当我们需要发送更新时,我们只需从内存映射中进行选择并发送更新即可。

Now, what if I have a cluster of tomcats and the user can connect to any node how do they share these suspended connections ? 现在,如果我有一个tomcat集群,并且用户可以连接到任何节点怎么办,他们如何共享这些暂停的连接? 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? 如何在集群环境中管理Websocket连接?
  • 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? 如何使用Spring有效地驱动您的消息驱动的应用程序?
  • and more... 和更多...

Spring 4 introduced websocket support with very cool features that answer a lot of your problems. Spring 4引入了具有非常酷的功能的websocket支持 ,可以解决许多问题。 In a clustered environment, Spring is recommending a MQ instance (that supports STOMP) such as RabbitMQ. 在集群环境中,Spring建议使用一个MQ实例(支持STOMP),例如RabbitMQ。 This MQ will manage topic subscriptions and messages distribution, while each tomcat will manage client connections. 此MQ将管理主题订阅和消息分发,而每个tomcat将管理客户端连接。

There are a couple of example applications that show how this works: a portfolio app and a chat app . 有两个示例应用程序展示了其工作原理: 组合应用程序聊天应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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