我试图通过为每个主题创建单独的会话来在同一连接中创建多个主题。主题和第一个耐用消费者都已成功创建,但在创建第二个消费者时出现错误。代码与单个主题完美配合,但我需要在同一连接中的运行时创建多个主题
以下是代码
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);
------------ 变量值 --------------
applicationId = "Test123"
getSelector(0) = "CID NOT LIKE 'Test123' AND Durability LIKE '0'"