3

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

G.G.
  • 592
  • 5
  • 16
  • Can anyone please help? – G.G. Dec 08 '18 at 09:17
  • I have tried various combinations of configuration and nothing worked for me. I am getting copy of message on each running instance. I have tried following: 1) No client id, no durability, same shared subscription name 2) Distinct client id, durability, same shared subscription name. 3) Distinct client id, no durability, same shared subscription name 4) Pub-sub domain true/false for all above three. None of the above helped in load balancing the messages over different instances. docs.tibco.com/products/tibco-enterprise-message-service-8-3-0 – G.G. Dec 10 '18 at 05:16

1 Answers1

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.

John Stringer
  • 558
  • 2
  • 6
  • This is not in my hand. Topic has been created by someone else.I am consuming data from topic. I have read in JMS and spring docs that it is feasible with JMS2.0. but looks like I am missing some config. Here is the jms link: https://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html – G.G. Dec 07 '18 at 16:15
  • 1
    Apologies you're right, I haven't actually used "shared subscriptions" at any point, all use cases where I've had to consume each message only once but have multiple consumers I've used queues. So my understanding might be incorrect but as I understand it, durable connections are relative to the "clientId"... If so presumably having 3 different clientIds means the you actually have 3 different durable subscriptions... As a starting point for investigation I'd try removing the durability and the clientIds... – John Stringer Dec 08 '18 at 17:26
  • I have tried various combinations of configuration and nothing worked for me. I am getting copy of message on each running instance. I have tried following: 1) No client id, no durability, same shared subscription name 2) Distinct client id, durability, same shared subscription name. 3) Distinct client id, no durability, same shared subscription name 4) Pub-sub domain true/false for all above three. None of the above helped in load balancing the messages over different instances. – G.G. Dec 10 '18 at 02:52
  • JMS 2.0 has the concept of "Shared Subscription" where a subscription can be shared across multiple consumers. With this feature publication will be delivered to only one of the consumer of a shared subscription thus sharing the workload. See this link https://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html. Check if your messaging provider supports JMS2.0 specification. – Shashi Dec 10 '18 at 03:53
  • @Shashi I am aware about shared subscription in JMS2.0 and it is mentioned in question as well that I am using this feature but still facing issue. I am using tibjms-8.x version and it supports JMS2.0 https://docs.tibco.com/products/tibco-enterprise-message-service-8-3-0 – G.G. Dec 10 '18 at 05:13
  • Sorry, did not notice that earlier. I do not have much knowledge of TIBCO. So can't comment on this problem. I guess it's worth posting the question in TIBCO forums. – Shashi Dec 10 '18 at 07:53