我不明白如何不在本地使用 ActiveMQ。
假设我有 2 台机器,它们需要交换一些消息。
在机器上我启动 ActiveMQ 代理:
> ~/bin/activemq
并使用类似的东西:
javax.naming.Context ctx = new InitialContext();
TopicConnectionFactory factory = (TopicConnectionFactory)ctx.lookup("connectionFactory");
conn = factory.createTopicConnection();
TopicSession session = conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = null;
try{
topic = (Topic)ctx.lookup("MyTopic");
System.out.println("MyTopic was found");
}catch(NameNotFoundException nnfe){
topic = session.createTopic("MyTopic");
System.out.println("MyTopic was created");
}
TextMessage textMessage = session.createTextMessage();
TopicPublisher publisher = session.createPublisher(topic);
conn.start();
textMessage.setText("My topic message number");
publisher.publish(textMessage);
System.out.println("sendMessage2topic");
在 jndi.properties 我有:
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
但是我应该在另一台机器上创建什么来订阅这个主题?我应该在第二台机器上创建第二个本地 ActiveMQ 代理,以及如何订阅第一台机器上的远程主题???