9 Replies Latest reply on Dec 11, 2007 1:40 PM by Danny Grasse

    connection factory to remote queue

    Danny Grasse Newbie

      I'm trying to connect to a remote JBoss queue from within a web application (also running in JBoss). The closest documentation I've found regarding this is http://wiki.jboss.org/wiki/Wiki.jsp?page=HowDoIConfigureAnMDBToTalkToARemoteQueue, but I'm not using EJBs. If that is the final answer, I could sure use some clarification on how to configure those xml snippets and exactly where they go and how to reference the queue.

      What I have expected to find is something telling me how to configure a connection factory that points to a remote location, and then in my code to reference that factory by its JNDI name and specify the remote "queue/<queue name>" value, just as I would do for a local queue.
      Am I thinking about this correctly? Any direction would be appreciated.

      dlgrasse

        • 1. Re: connection factory to remote queue
          Adrian Brock Master

          I don't understand how you were able to find a page about MDB configuration
          in the FAQ, but not this link that is above it?

          http://wiki.jboss.org/wiki/Wiki.jsp?page=HowDoIConfigureTheJMSResourceAdapterToUseARemoteConnectionFactory

          It's also the first hit if I type "Remote ConnectionFactory" into the WIKI search?
          http://www.jboss.com/search.jsp?query=Remote+ConnectionFactory&hitsPerPage=10

          • 2. Re: connection factory to remote queue
            Danny Grasse Newbie

            Thank you for the help. I had actually seen that one, too, and made some initial attempts with it. The couple of days I've spent on this, and the permutations of config values attempted, have me forgetting everything I've tried.
            Here's what I'm getting with trying the technique from the page mentioned:

            setup)

            - running JBoss 4.0.3sp1
            - local machine web app attempting to connect to "queue/EventQueue" on remote machine < queuehost >
            - added "remote-queues-service.xml" file to local 'deploy' directory
            - added "tx-connection-factory" tag to 'jms/jms-ds.xml' file
            - not using security realm

            1) tried it with almost verbatim what they show
            remote-queues-service.xml:
            <server>
             <mbean code='org.jboss.jms.jndi.JMSProviderLoader'
             name='jboss.mq:service=JMSProviderLoader,name=JMSProvider'
             >
             <attribute name='ProviderName'>DefaultJMSProvider</attribute>
             <attribute name='ProviderAdapterClass'>org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
             <attribute name='QueueFactoryRef'>java:/XAConnectionFactory</attribute>
             <attribute name='TopicFactoryRef'>java:/XAConnectionFactory</attribute>
             <attribute name='Properties'>
             java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
             java.naming.factory.url.pkgs=org.jnp.interfaces
             java.naming.provider.url=<queuehost>:1099
             </attribute>
             </mbean>
            </server>
            

            jms-ds.xml:
            <tx-connection-factory>
             <jndi-name>EventJmsXA</jndi-name>
             <xa-transaction/>
             <adapter-display-name>JMS Adapter</adapter-display-name>
             <config-property name='SessionDefaultType' type='java.lang.String'>javax.jms.Queue</config-property>
             <config-property name='JmsProviderAdapterJNDI' type='java.lang.String'>java:/DefaultJMSProvider</config-property>
             </tx-connection-factory>
            


            code binds to connection factory:
            EventJmsXA


            result:
            Trying to install an already registered mbean: jboss.mq:service=JMSProviderLoader,name=JMSProvider


            2) so i try with another name in the files:
            remote-queues-service.xml:
            <server>
             <mbean code='org.jboss.jms.jndi.JMSProviderLoader'
             name='jboss.mq:service=JMSProviderLoader,name=EventJMSProvider'
             >
             <attribute name='ProviderName'>EventJMSProvider</attribute>
             <attribute name='ProviderAdapterClass'>org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
             <attribute name='QueueFactoryRef'>java:/XAConnectionFactory</attribute>
             <attribute name='TopicFactoryRef'>java:/XAConnectionFactory</attribute>
             <attribute name='Properties'>
             java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
             java.naming.factory.url.pkgs=org.jnp.interfaces
             java.naming.provider.url=<queuehost>:1099
             </attribute>
             </mbean>
            </server>
            


            jms-ds.xml:
             <tx-connection-factory>
             <jndi-name>EventJmsXA</jndi-name>
             <xa-transaction/>
             <adapter-display-name>JMS Adapter</adapter-display-name>
             <config-property name='SessionDefaultType' type='java.lang.String'>javax.jms.Queue</config-property>
             <config-property name='JmsProviderAdapterJNDI' type='java.lang.String'>java:/EventJMSProvider</config-property>
             </tx-connection-factory>
            


            result:
            javax.naming.NameNotFoundException: EventJmsXA not bound
            <stacktrace>
            
            --- MBeans waiting for other MBeans ---
            ObjectName: jboss.jca:service=TxCM,name=EventJmsXA
             State: CONFIGURED
             I Depend On:
             jboss.jca:service=ManagedConnectionPool,name=EventJmsXA
             jboss.jca:service=CachedConnectionManager
             jboss:service=TransactionManager
             Depends On Me:
             jboss.jca:service=ConnectionFactoryBinding,name=EventJmsXA
            
            ObjectName: jboss.jca:service=ManagedConnectionPool,name=EventJmsXA
             State: CONFIGURED
             I Depend On:
             jboss.jca:service=ManagedConnectionFactory,name=EventJmsXA
             Depends On Me:
             jboss.jca:service=TxCM,name=EventJmsXA
            
            ObjectName: jboss.jca:service=ManagedConnectionFactory,name=EventJmsXA
             State: CONFIGURED
             I Depend On:
             jboss.jca:service=RARDeployment,name=''
             Depends On Me:
             jboss.jca:service=ManagedConnectionPool,name=EventJmsXA
            
            ObjectName: jboss.jca:service=ConnectionFactoryBinding,name=EventJmsXA
             State: CONFIGURED
             I Depend On:
             jboss.jca:service=TxCM,name=EventJmsXA
            
            --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
            ObjectName: jboss.jca:service=RARDeployment,name=''
             State: NOTYETINSTALLED
             Depends On Me:
             jboss.jca:service=ManagedConnectionFactory,name=EventJmsXA
            


            trying it with code binding to java:/EventJmsXA yields the same results.

            So my problem is that I try several variations on the basic documentation but cannot get it working. Am I just missing some simple detail?



            • 3. Re: connection factory to remote queue
              Adrian Brock Master

               

              "dlgrasse" wrote:

              1) tried it with almost verbatim what they show
              remote-queues-service.xml:
              <server>
               <mbean code='org.jboss.jms.jndi.JMSProviderLoader'
               name='jboss.mq:service=JMSProviderLoader,name=JMSProvider'
               >
               <attribute name='ProviderName'>DefaultJMSProvider</attribute>
              


              result:
              Trying to install an already registered mbean: jboss.mq:service=JMSProviderLoader,name=JMSProvider



              Is this really that hard to understand? There is already is an MBean
              with that name in jms-ds.xml, you need to use a different name (or remove
              the other one).

              e.g. The first example on the link I posted uses the following naming scheme:
              <mbean code="org.jboss.jms.jndi.JMSProviderLoader" name="jboss.mq:service=JMSProviderLoader,name=RemoteMQProvider,server=Whatever">
               <attribute name="ProviderName">WhateverJMSProvider</attribute>
              


              It's all explained in the docs (see the section describing the identities):
              http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigJMSProvider

              • 4. Re: connection factory to remote queue
                Danny Grasse Newbie

                Adrian,

                I appreciate your willingness to reply to my question. Thank you for your time.

                In the second part of my previous post I showed where I changed the name values, but still will failure (no queue found, plus some dependency issues). I've since corrected the dependencies (by adding in the <rar-name> tag). However, the queue is still not being resolved.

                I even tried adding a packet sniffer between the two machines to see if any attempt was made to connect to the remote server, but see nothing happening.
                You ask if it's hard to understand. My answer is that the examples are clear, though maybe not complete. I had no problem following what they say to do, but I'm suspecting there is something key missing.

                I have verified that I can ping the remote server's port. (BTW, one example showed 1099 while another showed 1100 as the remote port to connect to. There is no port 1100 open, but I can telnet to 1099 just fine and see that it's the org.jnp.server.NamingServer_Stub RMI instance.)

                For reference sake, here's exactly the current state of changes to the default config:

                added to jms/jms-ds.xml

                <mbean code='org.jboss.jms.jndi.JMSProviderLoader'
                 name='jboss.mq:service=JMSProviderLoader,name=EventJMSProvider,server=<remote queue server>'
                 >
                 <attribute name='ProviderName'>EventJMSProvider</attribute>
                 <attribute name='ProviderAdapterClass'>org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
                 <attribute name='FactoryRef'>java:/XAConnectionFactory</attribute>
                 <attribute name='QueueFactoryRef'>java:/XAConnectionFactory</attribute>
                 <attribute name='TopicFactoryRef'>java:/XAConnectionFactory</attribute>
                 <attribute name='Properties'>
                 java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                 java.naming.factory.url.pkgs=org.jnp.interfaces
                 java.naming.provider.url=<remote queue server>:1099
                 </attribute>
                 </mbean>
                ...
                <tx-connection-factory>
                 <jndi-name>EventJmsXA</jndi-name>
                 <xa-transaction/>
                 <rar-name>jms-ra.rar</rar-name>
                 <adapter-display-name>JMS Adapter</adapter-display-name>
                 <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
                 <config-property name='SessionDefaultType' type='java.lang.String'>javax.jms.Queue</config-property>
                 <config-property name='JmsProviderAdapterJNDI' type='java.lang.String'>java:/EventJMSProvider</config-property>
                 </tx-connection-factory>


                and in my code I connect to the ConnectionFactory using JNDI "java:/XAConnectionFactory",
                and the queue using JNDI name "queue/EventQueue"
                At startup of JBoss, the following error is seen:
                Jul 09 2007 09:33 | ERROR | PFApplicationServlet | An error occurred during servlet initialization. Reason follows:
                javax.naming.NameNotFoundException: EventQueue not bound
                at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
                at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
                at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
                at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
                at org.jnp.server.NamingServer.lookup(NamingServer.java:255)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                at javax.naming.InitialContext.lookup(InitialContext.java:351)



                dlgrasse

                • 5. Re: connection factory to remote queue
                  Adrian Brock Master

                  There are so many of the usual errors here it is unbelievable.

                  You need to go to the JNDI/Naming forum and read the FAQ referenced from the
                  "READ THIS FIRST" post.

                  e.g.
                  The most obvious is that the **in memory** jms connector java:/XAConnectionFactory
                  is not available remotely. Nothing in java:/ can be used remotely.

                  But also, you've created a local pooled jms connection factory with

                  <jndi-name>EventJmsXA</jndi-name>

                  (really java:/EventJmsXA in case you didn't spot that FAQ :-)
                  but then you're using a different name entirely in your code?

                  You really need to start a thread in the JNDI forum if that is what you don't understand.
                  None of this is JMS configuration.

                  • 6. Re: connection factory to remote queue
                    Adrian Brock Master

                     

                    "adrian@jboss.org" wrote:

                    But also, you've created a local pooled jms connection factory


                    Just in case this confuses you, the pool is local, but it pools remote connections.
                    All though in your case it doesn't since java:/XAConnectionFactory is unusable
                    remotely.

                    • 7. Re: connection factory to remote queue
                      Danny Grasse Newbie

                      Finally.

                      After looking at the FAQ, Wiki, and other useless documentation, the answer was indeed found in the JNDI forum - in a post: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=112107.

                      Forget all those <tx-connection-factory> and JMSProvider tags in the links offered earlier. (If you can get them to work for you, I'd love to see the exact configuration. But as far as I'm concerned the examples are incomplete at best, and incorrect at worst.) Here's how I got it to work for me.

                      Suppose you have JBoss server configured with a Queue running on it. Call this ServerQ, and the queue name is Q.
                      Now you want to connect to it remotely. If you were to do this from a stand-alone app, the answer is pretty simple - include 3 Properties values, which are easily provided via a jndi.properties file in the classpath.

                      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                      java.naming.provider.url=jnp://<ServerQ>:1099
                      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


                      And from your code you use ConnectionFactory jndi name "ConnectionFactory" and queue jndi ref "queue/Q". I've used that technique several times successfully.

                      You would expect that if you were asking how to do that very thing from within JBoss the answer would be pretty much that very thing - bind a jndi name to a remote connection factory - and nothing else. And in fact the solution that worked for me is exactly that. Add the following tag to your jms/jms-ds.xml file.

                      <mbean code='org.jboss.naming.ExternalContext'
                       name='jboss.jndi:service=ExternalContext,jndiName=<some jndi ref>'
                       >
                       <attribute name='JndiName'><some jndi ref></attribute>
                       <attribute name='Properties'>
                       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                       java.naming.factory.url.pkgs=org.jnp.interfaces
                       java.naming.provider.url=<ServerQ>:1099
                       </attribute>
                       <depends>jboss:service=Naming</depends>
                       </mbean>


                      Then from your code you reference the ConnectionFactory with jndi name "<some jndi ref>/ConnectionFactory" and the queue with jndi name "<some jndi ref>/queue/Q".

                      dlgrasse


                      • 8. Re: connection factory to remote queue
                        Mikael Larsson Newbie

                        Hi!

                        I've also been trying to send messages to a remote queue. Also got stuck on the "how do I lookup the remote queue" part...
                        Have seen
                        http://wiki.jboss.org/wiki/Wiki.jsp?page=HowDoIConfigureTheJMSResourceAdapterToUseARemoteConnectionFactory
                        but that does not explain how to get to the remote queue (at least not in a way so that I understand it...).

                        I've read the suggested solution with " bind a jndi name to a remote connection factory" by updating jms-ds.xml.

                        My question is:
                        With this configuration (updating jms-ds.xml) will the application server handle the connection supervision and do the necessary reconnect stuff if needed. I.e. do I have to implement a JMSConnectionExceptionListener. See also: http://wiki.jboss.org/wiki/Wiki.jsp?page=IGetIOExceptionPingTimeoutHowDoIFixIt
                        I would really like to avoid that (and digrasse too I guess).

                        Another question:
                        Is the suggested solution the same as:
                        http://jira.jboss.com/jira/browse/JBAS-1450?page=all
                        with the difference that this allows you to directly map the remote queue name in the jmx-ds.xml file?

                        /Mikael

                        • 9. Re: connection factory to remote queue
                          Danny Grasse Newbie

                          I regularly implement an ExceptionListener since that is what is always recommended. I wouldn't think that JBoss would reconnect your queue listener if it got disconnected.

                          dlgrasse