Connection conn = cf.createConnection();
conn.setClientID("Sausages");
Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSend.createProducer(topic);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
for (int i = 0; i < 10; i++)
{
TextMessage tm = sessSend.createTextMessage("message" + i);
prod.send(tm);
}
conn.close();
ServerManagement.stopServerPeer();
ServerManagement.startServerPeer();
// Messaging server restart implies new ConnectionFactory lookup
cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
ServerManagement.deployTopic("Topic");
conn = cf.createConnection();
conn.setClientID("Sausages");
sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
for (int i = 0; i < 10; i++)
{
TextMessage tm1 = (TextMessage)sub1.receive(3000);
assertNotNull(tm1);
if (tm1 == null)
{
break;
}
assertEquals("message" + i, tm1.getText());
TextMessage tm2 = (TextMessage)sub2.receive(3000);
assertNotNull(tm2);
if (tm2 == null)
{
break;
}
assertEquals("message" + i, tm2.getText());
TextMessage tm3 = (TextMessage)sub3.receive(3000);
assertNotNull(tm3);
if (tm3 == null)
{
break;
}