How to share messages, published on Topic, between multiple VMs, in Spring Jms Tibjms

久未见 提交于 2019-12-19 04:13:08

问题


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.

My requirement is that every consumer should receive distinct message i.e. no two consumer should get same message.

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

Currently I have following configuration :

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.

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. :)


回答1:


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.



来源:https://stackoverflow.com/questions/53672925/how-to-share-messages-published-on-topic-between-multiple-vms-in-spring-jms-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!