问题
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:
- spring jms 4.2.7
- Java jms 2.0
- tibco jms 8.0
- 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