2 Replies Latest reply on Sep 23, 2016 2:11 AM by Miroslav Novak

    how to sending message to other jboss server's queue

    Aaron Luo Newbie

      public void sendMsg() {

        QueueConnectionFactory factory = null;

        QueueConnection connection = null;;

        QueueSession queueSession = null;;

        TextMessage outMessage = null;;

        QueueSender queueSender = null;

        final String qcfLookup = "jms/factory/QCF";

        final String qLookup = "jms/queue/AUDIT_QUEUE";

        final String icf = "org.jboss.as.naming.InitialContextFactory";

        String url = "remote://";

        Hashtable environment = new Hashtable();

        environment.put(Context.INITIAL_CONTEXT_FACTORY, icf);

        environment.put(Context.PROVIDER_URL, url);

        try {

        Context ctx = new InitialContext(environment);

        factory = (QueueConnectionFactory) ctx.lookup(qcfLookup);

        Queue q1 = null;

        q1 = (Queue) ctx.lookup(qLookup);

        connection = factory.createQueueConnection();

        queueSession = connection.createQueueSession(false,


        queueSender = queueSession.createSender(q1);

        outMessage = queueSession.createTextMessage();



        } catch (Exception e) {

        // TODO Auto-generated catch block


        } finally {

        if (queueSender != null) try { queueSender.close(); } catch (Throwable e) {}

        if (queueSession != null) try { queueSession.close(); } catch (Throwable e) {}

        if (connection != null) try { connection.close(); } catch (Throwable e) {}




      i delpoy same ear on tow jboss eap.  i want send message to AUDIT_QUEUE form one to the other(ip is ) . but message always be sended to local AUDIT_QUEUE . the code like above. why the PROVIDER_URL not take effect.

        • 1. Re: how to sending message to other jboss server's queue
          Mike Finn Apprentice


          What EAP versions are you going between?


          The connection details vary in recent versions (5 vs 6 vs 7). I would recommend checking out the helloworld-jms quick start for the respective version. It has a sample remote JMS client in it. Note that if EAP 6 or 7 you have to add a destination name for the 'exported' version of your queue (accessible outside the JVM).


          From a design perspective, you may also want to consider using the JMS Bridge to communicate across instances. It will handle connectivity interruptions much better (where your current code would just fail-fast), and will scale much better.



          • 2. Re: how to sending message to other jboss server's queue
            Miroslav Novak Master

            It seems your code is correct so there might be issue in configuration. Just to double check - could you confirm that IP address is really address of the remote server (and not the local).


            How is "jms/factory/QCF" connection factory configured? To which server it's creating connections?