以下是一个示例代码,演示如何在 ActiveMQ Artemis 中使用选择器接收消息:
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); Connection connection = connectionFactory.createConnection(); try { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("MyQueue"); MessageConsumer consumer = session.createConsumer(queue, "myProperty='myValue'"); Message message = consumer.receive(); } finally { connection.close(); }