如何设计非EJB负载均衡应用程序?
我有一个 java 类 Processor 正在侦听 jms 主题,并且它正在努力跟上消息到达的速度,因此我们决定并发:
单个类侦听topic who 的工作是将消息分发给工作线程池,实际上是一个负载均衡器。它还必须防止 2 个工作人员为同一客户处理消息。
我预计互联网上会有很多关于此的信息,但所有内容似乎都表明使用 EJB,其中应用程序服务器管理池并进行平衡。我确信这一定是一个非常常见的问题,但似乎找不到任何库或设计模式来提供帮助。我是否从中获得了更多的收益,并且应该深入研究并编写自己的代码?
I have a java class Processor
that is listening to a jms topic and it is struggling to keep up with the speed in which messages are arriving so we've decided to go concurrent:
A single class listening to the topic who's job is to hand the messages out to a pool of worker threads, effectively being a load balancer. It also has to prevent 2 workers processing messages for the same customer.
I expected there to be quite a lot of information on the internet about this but everything seems to suggest the use of EJBs where the app server manages the pool and does the balancing. I'm sure this must be a really common problem, but can't seem to find any libraries or design patterns to assist. Am I making more out of it than it is and should just delve in and write my own code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不只使用队列而不是主题,并让同一应用程序的多个实例处理来自该队列的消息?
Why don't you just use a queue instead of a topic and have several instances of the same application handle messages from this queue ?
对于一群听众来说,这是一个很容易解决的问题。这就是应用程序服务器将为您做的事情。
我会得到一个好的应用程序服务器并使用它的 MDB 来快速解决这个问题。调整泳池的大小以跟上,你就会没事的。
如果您坚持编写自己的代码,请获得一个好的开源池实现并使用它。
如果必须是非EJB,请考虑Spring。它具有消息驱动的 POJO,这可能正是您所需要的。
This is an easy problem to solve with a pool of listeners. That's what the app server would be doing for you.
I'd get a good app server and use its MDBs to solve this quickly. Size the pool to keep up and you'll be fine.
If you insist on writing your own code, get a good open source pool implementation and use it.
If it must be non-EJB, consider Spring. It has message driven POJOs that could be just what you need.