I have such class:
public class XpathSelectorConsumer {
public static void main(String[] args) throws JMSException {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:55901");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TEST.QUEUE");
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
Message message = session.createTextMessage("<?xml version='1.0' encoding='UTF-8'?><notification>this is a test</notification>");
producer.send(message);
MessageConsumer consumer = session.createConsumer(destination, "XPATH '/notification'");
Message message2 = consumer.receive(10000);
System.out.println("Received message: " + message2);
producer.close();
session.close();
connection.close();
consumer.close();
}
}
When I run it, it always prints such string:
Received message: null
When I use no selector it returns all messages.
What am I doing wrong? How can I use XPath selectors?