How can one use activemq not locally?

rauch picture rauch · Feb 23, 2010 · Viewed 12.3k times · Source

I can't understand how to use ActiveMQ not locally.
Suppose I have 2 machines, which need to exchange some messages.
On the on machine I start ActiveMQ broker:

> ~/bin/activemq

and use something like:

    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");

where in jndi.properties I have:

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616

But what should I create on the other machine to subscribe on this topic? Shoul I create second local ActiveMQ broker ont the 2-nd machine, and how to subscribe on the remote topic that is on the first machine???

Answer

Elister picture Elister · Feb 23, 2010

localhost:61616 will make activeMQ listen on loopback(127.0.0.1) interface only. Use the IP of the machine or 0.0.0.0 instead.