0

I am building an application which will consumer messages from multiple topics, transform the message and then publish them to multiple topics. After looking up connectionfactory object, I am using this code

Connection con = cf.createConnection();
String clientId = "APP"+ con.hashCode();
con.setClientId(clientId);

and while creating durable subscribtion I am using this MessageConsumer consumer = session.CreateDurableSubscriber(topic,"DurableSubscribtion"+clientId, topic.getSelector, true);

Every connection should have unqiue client id and subscribtion name.

After a connection is closed and I try to access the same subscribtion again using hashCode of newly created connection, will this approach work? Or do i Need to specify subscritionnames like SUBSCRIBER1,SUBSCRIBER3,SUBSCRIBER2..

1 Answers1

0

Yeah, you have to specify a "repeatable" client id, so that you can present the same client id next time around. Otherwise, you will create loads (Integer.MAX_VALUE possibly ?) of subscriptions which will all be dead.

You need to devise a naming scheme that is meaningful. For example, if you had a subscriber per topic subscribed to, just name the client id <topic_name> + "durSub-Admin" or something.

If you're using ActiveMQ, this is a little easier on account of VirtualTopics.

Nicholas
  • 15,916
  • 4
  • 42
  • 66