4 Replies Latest reply on May 8, 2009 3:42 AM by Tim Fox

    How to send message to a remote queue

    Wayland Chan Newbie

      public class JMSSender {
      private Queue queue;

      private QueueConnectionFactory conFac;

      public void send(final String... msgsTxt) {

      Connection connection = null;
      Session session = null;
      try {
      connection = this.conFac.createConnection();
      session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); // tx will be commited by container...
      for (String txt: msgsTxt) {
      if (txt != null) {
      TextMessage msg = session.createTextMessage();
      MessageProducer producer = session.createProducer(queue);
      catch (JMSException ex) {
      throw new RuntimeException(ex);
      if(session != null){
      }catch(Exception ignored){}
      if(connection != null){
      }catch(Exception ignored){}

      The code above has no problem to send message to a local queue.
      How can I modify it or configure to make it to send to a remote queue?

      change the annotation
      @Resource(mappedName="/queue/myQueue") to
      seems not work.

      If I don't inject the connectionfactory and queue but using remote jndi lookup, it is okay to send the messages but session.commit() needed to be called after sending. (otherwise, the message is not sent)
      That's not what I want as it should be container managed.
      How to send the message to remote queue in the container managed transaction? Thanks.

        • 1. Re: How to send message to a remote queue
          Wayland Chan Newbie

          finally solved.
          Forgot to add remote ip address to the connection factory.
          e.g. @Resource(mappedName="jnp://remotehost:1099/ConnectionFactory")

          • 2. Re: How to send message to a remote queue
            vandana awat Newbie


            could you please tell how's your jms-ds.xml configured to interact with the remote queues

            i have tried the approach of


            but can't get it to work
            i'm not using EJB i want to use it in a web app...
            your help would be greatly appreciated ..

            • 3. Re: How to send message to a remote queue
              Clebert Suconic Master

              That's pretty much the procedure.

              - you define a JMSPRoviderLoader. Give it a name

               <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
               <attribute name="ProviderName">MyProvider</attribute>
               <attribute name="ProviderAdapterClass">
               <!-- The queue connection factory -->
               <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
               <!-- The topic factory -->
               <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
               <!-- Uncomment to use HAJNDI to access JMS
               <attribute name="Properties">

              - you define the tx-connection-factory. make a reference to the provider loader using the property JmsProviderAdapterJNDI. Also define a JNDI name for the tx-connection-factory

               <adapter-display-name>JMS Adapter</adapter-display-name>
               <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
               <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/MyProvider</config-property>

              - In your code, use refer to JNDI name from tx-connection-factory:

              javax.jms.ConnectionFactory factory = (javax.jms.ConnectionFactory)jndi.lookup("java:/MyConnectionFactory");

              But all this is already defined on that Wiki. So I'm already providing you extra information.

              • 4. Re: How to send message to a remote queue
                Tim Fox Master

                Also this is a question on JCA configuration, not JBoss Messaging config.

                None of the above config is JBM config.

                Please ask in the JCA user forum.