为 Java 客户端实现故障转移模式的最佳方法
我们正在设计一个Java客户端(将部署在Tomcat、Windows 2008 R2上),它需要订阅Sonic MQ上的一些JMS主题。
客户端希望该 Java 客户端具有冗余性,并且在任何时间点,只能有一个订阅者订阅主题。
我们的要求与此帖子类似。
是否有为此目的而构建的标准化开源项目,或者我们必须编写自己的代码来检查服务器运行状况(耗时)? 实现这个 Java 客户端的最佳方法是什么?
我们正在探索以下用于消费 JMS 消息的技术:
- Spring 集成
- Apache Camel
我们的方向正确吗?我们应该能够动态启动/停止主题的订阅。
We are designing a Java client (will be deployed on Tomcat, Windows 2008 R2) which needs to subscriber for some JMS topics on Sonic MQ.
Client wants to have to redundancy for this Java client and at any point of time, only one subscriber should be subscribed for topics.
Our requirement is similar to the this post.
Is there's any standardized open source project which is built for this purpose or we have to write our own code to check the server health (time-consuming)?
What's the best way to implement this Java Client.
We are exploring the below technologies for consuming JMS messages:
- Spring Integration
- Apache Camel
Are we going in the right direction? We should be able to start/stop the subscriptions to the topics on fly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Apache Camel 有类似这样的开箱即用的东西,请检查这个。它实现了EAI负载均衡器模式。您可以选择“故障转移”策略。似乎正在使用异常来决定接下来要使用哪个处理器。
其他方法可以是在订阅者之间实现基于简单自定义 jms 的心跳,以跟踪彼此的运行状况并平衡负载或故障转移。每个订阅者都可以跟踪他们应该处理的内容。例如,从您提供的链接中,每个订阅者都知道它正在侦听的主题,并在心跳失败的情况下继续接收来自其他订阅者的心跳,故障转移侦听器将开始为失败的侦听器获取消息。我认为您可以使用 JMS 消息选择器来实现过滤器。一个很好的开始参考可以是 this Javaworld 上的旧文章。
Apache Camel have something like this out of the box check this. It implements EAI Load Balancer pattern. You can choose "Failover" Policy. seems to be using Exception to decide which processor to go next.
Other way to do can be to implement simple custom jms based hearbeats among subscribers to keep track of each other health and balance load or failover. Each Subscriber can keep track of what they are suppose to process. For example from the link you provided each subscriber knows the subject it is listening to and keep receiving hearbeat from other subscriber in case of heartbeat failure failover listener will start taking messages for failed listener. I think you can use JMS Message Selector to implement filters. A good reference to start with can be this old article on Javaworld.