简体   繁体   English

多个集群监听同一个JMS消息队列

[英]Multiple clusters listening to the same JMS messaging queue

I've been searching for a JMS solution and I (surprisingly) haven't been able to find an easy answer. 我一直在寻找JMS解决方案,而我(令人惊讶地)一直没有找到简单的答案。 I may be searching for the wrong thing, so hopefully the community on stackoverflow can help. 我可能正在搜索错误的内容,因此希望stackoverflow上的社区可以为您提供帮助。

What I'm working should be pretty basic: Using JMS for event notification across clusters of microservices. 我正在工作的东西应该很基本:使用JMS在微服务集群之间进行事件通知。 The setup is simple. 设置很简单。 Suppose I have 3 clusters, each with 3 instances all separate from each other running on their own EE server instances on different machines. 假设我有3个集群,每个集群有3个实例,它们彼此分开,分别在不同计算机上的EE服务器实例上运行。

Cluster A
 A1, A2, A3

Cluster B
  B1, B2, B3

Cluster C
  B1, B2, B3

And I have a central JMS server which has a queue they all listen to: 我有一个中央JMS服务器,该服务器有一个队列,所有人都在听:

A1, A2, A3 |
B1, B2, B3 |<-------> JMS Queue (Q1)
C1, C2, C3 |

Microservice instance A2 processes a request and publishes Message (M) onto (Q1). 微服务实例A2处理请求并将消息(M)发布到(Q1)。 What I want to happen is that for each of the other clusters - B,C - one instance in that cluster picks up the message and processes it for the cluster. 我想要发生的是,对于每个其他群集-B,C-该群集中的一个实例接收消息并为该群集处理消息。 It obviously doesn't matter which instance picks it up as long as it is only processed one time per cluster. 只要每个集群仅处理一次,显然哪个实例选择它并不重要。 So it would look like 所以看起来像

A2 | ---> publish (M) ----> JMS Queue (Q1)


B2 |
   | <---- (M) <----- JMS Queue (Q1)
C1 |

This seems like a very common, almost default setup that everyone would need. 这似乎是每个人都需要的非常常见的,几乎是默认的设置。 But so far what I've found with the way queues work is that once (M) get published to (Q1) then only one of B1,B2,B3,C1,C2,C3 will pick it up and process it and not one from each cluster like I'm looking for. 但是到目前为止,我发现队列的工作方式是,一旦(M)发布到(Q1),那么只有B1,B2,B3,C1,C2,C3中的一个会选择并处理它,而不是一个从每个集群中寻找我。 If I use a Topic, then every instance in every cluster would get a message so it doesn't seem like this is what I'm looking for either. 如果我使用主题,那么每个群集中的每个实例都会收到一条消息,因此这似乎并不是我所要的。

So that's it. 就是这样了。 Thoughts? 思考? Thanks in advance! 提前致谢!

We used topic to resolve this issue. 我们使用主题来解决此问题。 So instead of JMS queue use JMS topic. 因此,请使用JMS主题代替JMS队列。 Have all the web applications on all cluster subscribe to this topic. 让所有群集上的所有Web应用程序都订阅该主题。 We also have a writer component so that all of them can write to the topic. 我们还有一个writer组件,因此他们所有人都可以写这个话题。

Cluster A:
webapp1 --> StatusTopic (JMS Topic)
webapp2 --> StatusTopic (JMS Topic)

Cluster B:
webapp1 --> StatusTopic (JMS Topic)
webapp2 --> StatusTopic (JMS Topic)

refer this site: jms-clustering-example 请参考此站点: jms-clustering-example

as a solution we use 作为我们使用的解决方案

ClusteredConnectionFactory ClusteredConnectionFactory

which help to make multiple consumers from the same queue(provide load balancing between consumer). 这有助于使多个使用者来自同一队列(提供使用者之间的负载平衡)。

java.naming.provider.url java.naming.provider.url的

on which we have to assign dynamic URLs of the consumers. 我们必须在其上分配使用者的动态URL。

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

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