如何在Spring Jms Tibjms中在多个VM之间共享主题上发布的消息 [英] How to share messages, published on Topic, between multiple VMs, in Spring Jms Tibjms

查看:506
本文介绍了如何在Spring Jms Tibjms中在多个VM之间共享主题上发布的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在使用发布到主题的消息。我有3台运行我的应用程序代码的服务器。通过当前实现,消息被分发到所有正在运行的VM,即每个消费者都接收消息的副本。

My application is consuming messages published to a Topic. I have 3 servers where my application code is running. With current implementation, the messages is distributed to all running VMs i.e. copy of message is received by every consumer.

我的要求是每个消费者都应该收到不同的消息即没有两个消费者应该得到相同的消息。

以下是我正在使用的库:

Below are the libraries I am using:


  1. spring jms 4.2.7

  2. Java jms 2.0

  3. tibco jms 8.0

  4. wildfly-swarm as server

  1. spring jms 4.2.7
  2. Java jms 2.0
  3. tibco jms 8.0
  4. wildfly-swarm as server

目前我有以下配置:

TibjmsConnectionFactory factory = new TibjmsConnectionFactory("server-url");
factory.setUserName("username");
factory.setUserPassword("password");
factory.setClientID("clientId");

DefaultMessageListenerContainer listener = new DefaultMessageListenerContainer();
listener.setPubSubDomain(true);
listener.setMessageListener(myMessageListener);
listener.setDestination(new TibjmsTopic("topic"));
listener.setConnectionFactory(factory);
listener.setSessionTransacted(true);
listener.setSessionAutoAcknowledged(Session.CLIENT_ACKNOWLEDGE);
listener.setSubscriptionDurable(true);
listener.setDurableSubscriptionName("subscription");
listener.setSubscriptionShared(true);

但是,它没有做我期待的事情。使用上面的配置,所有消费者都收到所有消息。

But, it is not doing what I am expecting. Using above config, all consumers are receiving all the messages.

只是要添加,我在所有正在运行的实例中指定了相同的DurableSubscriptionName但不同的ClientId。

Just to add, I have specified same DurableSubscriptionName but distinct ClientId across all running instances.

我缺少什么配置?有人可以帮忙吗?非常感谢提前。 :)

What configuration I am missing? Can anyone help please? Thanks a ton in advance. :)

推荐答案

不要使用主题,使用队列......按设计主题是pub / sub和所有订阅者到一个主题将收到所有已发布的消息。队列是一对一的,如果队列中有多个消费者,每个消息都会得到不同的消息。

Don't use a topic, use a queue... Topics by design are pub/sub and all subscribers to a topic will receive all published messages. Queues are one in one out, if you have multiple consumers on a queue each get different messages.

这篇关于如何在Spring Jms Tibjms中在多个VM之间共享主题上发布的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆