doTestVirtualTopicCreation(10);
}
public void doTestVirtualTopicCreation(int total) throws Exception {
ConsumerBean messageList = new ConsumerBean() {
public synchronized void onMessage(Message message) {
super.onMessage(message);
if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
try {
message.acknowledge();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
};
messageList.setVerbose(true);
String queueAName = getVirtualTopicConsumerName();
// create consumer 'cluster'
ActiveMQQueue queue1 = new ActiveMQQueue(queueAName);
ActiveMQQueue queue2 = new ActiveMQQueue(queueAName);
Session session = createStartAndTrackConnection().createSession(false, ackMode);
MessageConsumer c1 = session.createConsumer(queue1);
session = createStartAndTrackConnection().createSession(false, ackMode);
MessageConsumer c2 = session.createConsumer(queue2);
c1.setMessageListener(messageList);
c2.setMessageListener(messageList);
// create topic producer
Session producerSession = createStartAndTrackConnection().createSession(false, ackMode);
MessageProducer producer = producerSession.createProducer(new ActiveMQTopic(getVirtualTopicName()));
assertNotNull(producer);
for (int i = 0; i < total; i++) {
producer.send(producerSession.createTextMessage("message: " + i));
}
messageList.assertMessagesArrived(total);
// do twice so we confirm messages do not get redelivered after client acknowledgement
if( doneTwice == false ) {
doneTwice = true;
doTestVirtualTopicCreation(0);