I am trying to create multiple topics within same connection by creating separate session for each topic. both Topics and 1st durable consumer created successfully but I am getting error while creating 2nd consumer. Code work perfect with single topic but I need to create multiple topics in run time within same connection
Following is the code
activemq::library::ActiveMQCPP::initializeLibrary();
// create connection factory
auto_ptr<ConnectionFactory> connectionFactory(ConnectionFactory::createCMSConnectionFactory(brokerURI));
// create a connection
connection = connectionFactory->createConnection(uname,pwd,applicationId);
connection->setExceptionListener(this);
// adding transport listener
ActiveMQConnection* amqConnection = dynamic_cast<ActiveMQConnection*>( connection );
amqConnection->addTransportListener( this );
// create a session
session[0] = connection->createSession( Session::AUTO_ACKNOWLEDGE );
session[1] = connection->createSession( Session::AUTO_ACKNOWLEDGE );
destination[0] = session[0]->createTopic(serviceTopic);
topic[0] = session[0]->createTopic(serviceTopic);
destination[1] = session[1]->createTopic(serviceTopic2);
topic[1] = session[1]->createTopic(serviceTopic2);
producer[0] = session[0]->createProducer(destination[0]);
producer[1] = session[1]->createProducer(destination[1]);
consumerDurable[1] = session[1]->createDurableConsumer(topic[1], applicationId, getSelector(0), false);
consumerDurable[1]->setMessageListener(this);
consumerDurable[0] = session[0]->createDurableConsumer(topic[0], applicationId, getSelector(1), false);
consumerDurable[0]->setMessageListener(this);
------------ Variable values --------------
applicationId = "Test123"
getSelector(0) = "CID NOT LIKE 'Test123' AND Durability LIKE '0'"
Take a look at this help page on ActiveMQ. It explains how durable subscriptions work against a topic. In particular this:
JMS specification dictates that the identification of S is done by a combination of the clientID and the durable subscriber name. This is so that the JMS connection S uses can have many different durable subscriptions on different topics or on the same topic with different selectors - yet the JMS provider can know which message for which subscription to keep around for it.
You need to use different IDs for different consumers.