8 Replies Latest reply on Aug 27, 2009 7:57 AM by moonbird79

    JNDI lookup from JBoss embedded MQ Provider

      Hi,

      i have successfully embedded ActiveMQ via JCA/RA in JBoss 5.1:
      http://activemq.apache.org/integrating-apache-activemq-with-jboss.html

      Now I like to use JNDI to lookup ActiveMQs ConnectionFactory and the Destinations from a java/jms client outside the application server.

      My Problem is, that i get a null pointer object back form jndi lookup, and this is obviously not new:
      http://www.nabble.com/JBoss-and-ActiveMQ-with-remote-JNDI-to16961289.html#a16961289

      In this thread some JBoss guy writes about this architecture problem:
      JBoss answer
      "/The connection factories provided by a Resource Adapter (RA) are
      typically not available for use by clients that are outside of the
      application server. That is, the JCA specification is intended to
      provided resources to the application server, and relies upon behavior
      on the part of the application server in connection pool management,
      transaction management, and security.

      Also, for this reason, the JNDI location of the RA's ConnectionFactories
      should be located in the "java:" namespace. This namespace is local to
      the jvm and has no visibility to external clients./"

      So my question is, may I use MQ Providers from Clients outside the application server or may i only use it via EJB components like MDBs ?

      I am confused - because JBoss Messaging is (as far as i know) also embedded via JCA and also bound to global JNDI and - I can successfully lookup the JBoss Messaging ConnectionFactory from a client outside !!! Why does it work - is this bug a feature ? ;-)

      Thx so far !

        • 1. Re: JNDI lookup from JBoss embedded MQ Provider

          This is my code fragment, after the jndi lookup conectionfactory and the destination are both null :-( :

          // initialize jndi connection (jboss specific configuration)
           Properties props = new Properties();
           props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
           props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
           props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
           //props.setProperty("j2ee.clientName", "TestClient");
          
           // this is from http://activemq.apache.org/jndi-support.html
           //props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
           //props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");
          
          
           // declare all variables for jndi and message transfer needed
           Context ctx = null;
           ActiveMQConnectionFactory queueConnectionFactory = null;
           QueueConnection queueConnection = null;
           QueueSession queueSession = null;
           Queue stationInfoQueue = null;
           MessageProducer msgProducer = null;
           TextMessage textMessage = null;
          
           // create new initial context from jndi
           try
           {
           ctx = new InitialContext(props);
           }
           catch (NamingException e)
           {
           System.out.println("Could not create JNDI API context: " + e);
           System.exit(1);
           }
          
           // Look up connection factory and destination
           try
           {
           ConnectionFactory factory = (ConnectionFactory) ctx.lookup("activemq/QueueConnectionFactory");
           //queueConnectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
          
           stationInfoQueue = (Queue) ctx.lookup("stationInfoQueue");
          
           if (factory == null)
           {
           System.out.println("NULL for queueConnectionFactory");
           }
          
           if (stationInfoQueue == null)
           {
           System.out.println("NULL for stationInfoQueue");
           }
           }
           catch (NamingException e)
           {
           System.out.println("JNDI API lookup failed:" + e);
           System.exit(1);
           }
          


          • 2. Re: JNDI lookup from JBoss embedded MQ Provider

            This is my datasource for the activemq provider:

            <?xml version="1.0" encoding="UTF-8"?>
            
            <!DOCTYPE connection-factories
             PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
             "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
            
            <connection-factories>
            
             <tx-connection-factory>
             <jndi-name>activemq/QueueConnectionFactory</jndi-name>
             <xa-transaction/>
             <use-java-context>false</use-java-context>
             <track-connection-by-tx/>
             <rar-name>activemq-ra.rar</rar-name>
             <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
             <ServerUrl>vm://localhost</ServerUrl>
             <!--
             <UserName>sa</UserName>
             <Password></Password>
             -->
             <min-pool-size>1</min-pool-size>
             <max-pool-size>200</max-pool-size>
             <blocking-timeout-millis>30000</blocking-timeout-millis>
             <idle-timeout-minutes>3</idle-timeout-minutes>
             </tx-connection-factory>
            
             <tx-connection-factory>
             <jndi-name>activemq/TopicConnectionFactory</jndi-name>
             <xa-transaction/>
             <track-connection-by-tx/>
             <rar-name>activemq-ra.rar</rar-name>
             <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
             <ServerUrl>vm://localhost</ServerUrl>
             <!--
             <UserName>sa</UserName>
             <Password></Password>
             -->
             <min-pool-size>1</min-pool-size>
             <max-pool-size>200</max-pool-size>
             <blocking-timeout-millis>30000</blocking-timeout-millis>
             <idle-timeout-minutes>3</idle-timeout-minutes>
             </tx-connection-factory>
            
             <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">
             <attribute name="JNDIName">stationInfoQueue</attribute>
             <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
             <attribute name="Type">javax.jms.Queue</attribute>
             <attribute name="Properties">PhysicalName=queue.outbound</attribute>
             </mbean>
            
             <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">
             <attribute name="JNDIName">activemq/topic/inbound</attribute>
             <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
             <attribute name="Type">javax.jms.Topic</attribute>
             <attribute name="Properties">PhysicalName=topic.inbound</attribute>
             </mbean>
            
            </connection-factories>
            




            and this is the result of my GLOBAL JNDI Namespace (JBoss Console):

            +- activemq (class: org.jnp.interfaces.NamingContext)
            | +- topic (class: org.jnp.interfaces.NamingContext)
            | | +- inbound (class: org.apache.activemq.command.ActiveMQTopic)
            | +- QueueConnectionFactory (class: org.apache.activemq.ra.ActiveMQConnectionFactory)
            +- stationInfoQueue (class: org.apache.activemq.command.ActiveMQQueue)
            +- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)

            • 3. Re: JNDI lookup from JBoss embedded MQ Provider

              ... and as far as this site describes:

              http://activemq.apache.org/jndi-support.html

              "ActiveMQ will work with any JNDI provider capable of storing Java objects."

              • 4. Re: JNDI lookup from JBoss embedded MQ Provider

                and - if i uncomment:

                //queueConnectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);

                it works - but - without jndi support :-( and ActiveMQConnectionFactory is not a JMS API call ! :-(

                • 5. Re: JNDI lookup from JBoss embedded MQ Provider

                  for alle people who dont know why my connectionfactory is available in the (not common for jca ressource adapter) GLOBAL jndi namespace, you have to use:

                  <use-java-context>false</use-java-context>

                  ... in your datasource file. ;-)

                  • 6. Re: JNDI lookup from JBoss embedded MQ Provider
                    vickyk

                     

                    "moonbird79" wrote:

                    +- activemq (class: org.jnp.interfaces.NamingContext)
                    | +- topic (class: org.jnp.interfaces.NamingContext)
                    | | +- inbound (class: org.apache.activemq.command.ActiveMQTopic)
                    | +- QueueConnectionFactory (class: org.apache.activemq.ra.ActiveMQConnectionFactory)
                    +- stationInfoQueue (class: org.apache.activemq.command.ActiveMQQueue)
                    +- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)


                    The following call should work
                    ConnectionFactory factory = (ConnectionFactory) ctx.lookup("activemq/QueueConnectionFactory");


                    What error do you get when this is called?
                    Does this configuration work in JBoss4.x series?


                    • 7. Re: JNDI lookup from JBoss embedded MQ Provider

                      ...this is what i tryed :-/ the lookup call throw no exceptions but the queueConnectionFactory object is null (i got the output NULL for queueC...).
                      STRANGE :-(

                      if i try to create a new queueConnection like this:

                      queueConnection = queueConnectionFactory.createQueueConnection();

                      ... of course - i get a null pointer exception :-/

                      ... i use JBoss 5.1 GA

                      • 8. Re: JNDI lookup from JBoss embedded MQ Provider