要解决ActiveMQ Artemis中通配符路由不起作用的问题,可以按照以下步骤进行排查和修复:
...
...
...
...
...
...
...
...
...
...
...
true
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
true
确保
设置为true
。
topic://
前缀和通配符#
或*
来匹配所有主题。示例如下:import javax.jms.*;
public class MessageSender {
public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("topic://mytopic/#"); // 使用#通配符匹配所有mytopic下的子主题
MessageProducer producer = session.createProducer(topic);
TextMessage message = session.createTextMessage("Hello, World!");
producer.send(message);
session.close();
connection.close();
}
}
确保使用正确的通配符格式来匹配目标地址。
topic://
前缀和通配符#
或*
来匹配所有主题。示例如下:import javax.jms.*;
public class MessageReceiver {
public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("topic://mytopic/#"); // 使用#通配符匹配所有mytopic下的子主题
MessageConsumer consumer = session.createConsumer(topic);
consumer.setMessageListener(new MessageListener() {
@