activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Brewer-Davis <mich...@tech4learning.com>
Subject multicast discovery - localhost in UDP packets
Date Wed, 20 Oct 2010 14:48:01 GMT
I'm trying to implement broker discovery using ActiveMQ 5.4.0.  I've 
been successful using multiple JVMs on one host, but I'm unable to set 
up a network between hosts.

My simplest attempt has been to use the peer: transport.  The UDP 
messages passed have the contents:

     redgroup.ActiveMQ-4.alive.%localhost%tcp://127.0.0.1:53890

The localhost address obviously doesn't resolve properly on the second 
host.  But "localhost" values are hardcoded in PeerTransportFactory 
(line 94) and in MulticastDiscoveryAgent (line 412).

Wiring the peer transport manually (a tcp://0.0.0.0:0 TransportConnector 
with a multicast discovery URI), I can get the message to include 
tcp://Michael-Dell:XXXXX, but that hostname isn't a real network 
location--just my local computer name.

Any advice?

Here's the simplest version of my initial test with the peer: transport.

     private static final String CONNECTION_URI = 
"peer://redgroup/brokerA?persistent=false";
     private static final String TOPIC_NAME = "topicX";

             ActiveMQConnectionFactory factory
                 = new ActiveMQConnectionFactory(CONNECTION_URI);

             Connection connection = factory.createConnection();
             Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
             Topic topic = session.createTopic(TOPIC_NAME);
             MessageProducer createProducer = session.createProducer(topic);

             connection.start();

             while (true) {
                 TextMessage message = session.createTextMessage("Hello, 
world!");
                 System.out.println("send: " + message);
                 createProducer.send(message);
                 Thread.sleep(1000);
             }

The receiver instantiates the factory using the same variables but adds 
a consumer instead:

             ActiveMQConnectionFactory factory
                 = new ActiveMQConnectionFactory(CONNECTION_URI);

             Connection connection = factory.createConnection();
             Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
             Topic topic = session.createTopic(TOPIC_NAME);

             MessageConsumer consumer = session.createConsumer(topic);
             consumer.setMessageListener(new MessageListener() {
                public void onMessage(Message m) {
                    System.out.println("recv: " + m);
                }
             });

             connection.start();


Mime
View raw message