TopicSubscriber select = session1.createSubscriber(topic, "Selector = 'select'", false);
TopicSubscriber normal = session1.createSubscriber(topic);
TopicPublisher publisher = session1.createPublisher(topic);
con.start();
TextMessage m;
TextMessage message;
//send message to all consumers
publisher.publish(session1.createTextMessage("hello-new2"));
session1.commit();
//test normal subscriber gets message
m = (TextMessage) normal.receive(1000);
assertNotNull(m);
session1.commit();
//test selector subscriber doesn't message
m = (TextMessage) select.receive(1000);
assertNull(m);
session1.commit();
//test nolocal subscriber doesn't message
m = (TextMessage) noLocal.receive(1000);
if (m != null)
{
System.out.println("Message:" + m.getText());
}
assertNull(m);
//send message to all consumers
message = session1.createTextMessage("hello2");
message.setStringProperty("Selector", "select");
publisher.publish(message);
session1.commit();
//test normal subscriber gets message
m = (TextMessage) normal.receive(1000);
assertNotNull(m);
session1.commit();
//test selector subscriber does get message
m = (TextMessage) select.receive(1000);
assertNotNull(m);
session1.commit();
//test nolocal subscriber doesn't message
m = (TextMessage) noLocal.receive(100);
assertNull(m);
AMQConnection con2 = (AMQConnection) getClientConnection("guest", "guest", "foo");
TopicSession session2 = con2.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
TopicPublisher publisher2 = session2.createPublisher(topic);
message = session2.createTextMessage("hello2");
message.setStringProperty("Selector", "select");
publisher2.publish(message);
session2.commit();
//test normal subscriber gets message
m = (TextMessage) normal.receive(1000);
assertNotNull(m);