无法在ActiveMQ使用者中使用XPath选择器

时间:2013-11-18 10:05:58

标签: java xpath selector activemq

我有这样的课程:

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();
  }
}

当我运行它时,它总是打印这样的字符串:

Received message: null

当我不使用选择器时,它会返回所有消息。

我做错了什么?我如何使用XPath选择器?

1 个答案:

答案 0 :(得分:1)

我在activemq classpath中没有xalan.jar。问题解决了。感谢