I'm trying to track down an problem where a queue browser on a VM
connection to one AMQ broker is sometimes not seeing messages put on a
queue from a VM connection to another broker in the same network. The
code below can recreate the problem, running the put() on JVM and the
browse() on another JVM the first QueueBrowser never sees the message
but the second QueueBrowser does though sometimes it doesn't without
the Thread.sleep for a few seconds.

Is there anything obviously wrong with this setup or are there any
config settings that could help?

   ...ant

The code to put a message on a queue:

    public void put() throws Exception {
        BrokerService broker1 = new BrokerService();
        broker1.setBrokerName("default");
        broker1.setPersistent(false);
        broker1.setUseJmx(false);
        TransportConnector tc = broker1.addConnector("tcp://localhost:0");
        tc.setDiscoveryUri(URI.create("multicast://default"));
        broker1.addNetworkConnector("multicast://default");
        broker1.start();

        Connection conn1 = new
ActiveMQConnectionFactory("vm://default?create=false").createConnection();
        conn1.start();
        Session sess1 = conn1.createSession(false, 1);
        Queue d1 = sess1.createQueue("d1");
        MessageProducer p1 = sess1.createProducer(d1);
        TextMessage m1 = sess1.createTextMessage("test");
        p1.send(m1);
   }


The code to browse the messages on the queue:

    public void browse() throws Exception {

        BrokerService broker2 = new BrokerService();
        broker2.setBrokerName("default");
        broker2.setPersistent(false);
        broker2.setUseJmx(false);
        TransportConnector tc = broker2.addConnector("tcp://localhost:0");
        tc.setDiscoveryUri(URI.create("multicast://default"));
        broker2.addNetworkConnector("multicast://default");
        broker2.start();

        Connection conn2 = new
ActiveMQConnectionFactory("vm://default?create=false").createConnection();
        conn2.start();
        Session sess2 = conn2.createSession(false, 1);
        Queue d1 = sess2.createQueue("d1");
        QueueBrowser b = sess2.createBrowser(d1);

        Enumeration x2 = b.getEnumeration();
        while (x2.hasMoreElements()) {
            System.out.println(x2.nextElement()); // this never gets
the message
        }

        Thread.sleep(5000);

        b = sess2.createBrowser(d1);
        Enumeration x2a = b.getEnumeration();
        while (x2a.hasMoreElements()) {
            System.out.println(x2a.nextElement()); // this does get the message
        }

    }

Reply via email to