conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
AMQTopic topic = new AMQTopic((AMQConnection) conn, "testResubscribeWithChangedSelectorNoClose");
// Create durable subscriber that matches A
TopicSubscriber subA = session.createDurableSubscriber(topic,
"testResubscribeWithChangedSelectorNoClose",
"Match = True", false);
// Reconnect with new selector that matches B
TopicSubscriber subB = session.createDurableSubscriber(topic,
"testResubscribeWithChangedSelectorNoClose",
"Match = false", false);
// First subscription has been closed
try
{
subA.receive(1000);
fail("First subscription was not closed");
}
catch (Exception e)
{
e.printStackTrace();
}
conn.stop();
// Send 1 matching message and 1 non-matching message
MessageProducer producer = session.createProducer(topic);
TextMessage msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart1");
msg.setBooleanProperty("Match", true);
producer.send(msg);
msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart2");
msg.setBooleanProperty("Match", false);
producer.send(msg);
// should be 1 or 2 messages on queue now
// (1 for the java broker due to use of server side selectors, and 2 for the cpp broker due to client side selectors only)
AMQQueue queue = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorNoClose");
assertEquals("Queue depth is wrong", isJavaBroker() ? 1 : 2, ((AMQSession<?, ?>) session).getQueueDepth(queue, true));
conn.start();
Message rMsg = subB.receive(POSITIVE_RECEIVE_TIMEOUT);
assertNotNull(rMsg);
assertEquals("Content was wrong",
"testResubscribeWithChangedSelectorAndRestart2",
((TextMessage) rMsg).getText());
rMsg = subB.receive(1000);
assertNull(rMsg);
// Check queue has no messages
assertEquals("Queue should be empty", 0, ((AMQSession<?, ?>) session).getQueueDepth(queue, true));