3 Replies Latest reply on Apr 4, 2005 8:00 PM by disrael

    JBossMQ under other application servers

    ben.lindahl

      Is JBossMQ able to function under other application servers? Our product ships with JBoss, but we want to give clients the option to switch out the application server without providing their own JMS implementations.

      Thanks in advance.

        • 1. Re: JBossMQ under other application servers
          narayanrm

          Yes It works. All you have to do is to configure JBOSS MQ as external JNDI Provider in the other Application Server. If you are using a session Bean you can lookup for the external JNDI and if you have to configure the MDB for that in case of Weblogic it gives a provision like

           <message-driven-descriptor>
           <pool>
           <max-beans-in-free-pool>...</max-beans-in-free-pool>
           <initial-beans-in-free-pool>...</initial-beans-in-free-pool>
           </pool>
           <destination-jndi-name>...</destination-jndi-name>
           <initial-context-factory>...</initial-context-factory>
           <provider-url> </provider-url>
           <connection-factory-jndi-name>..<connection-factory-jndi-name>
           <jms-client-id>.... </jms-client-id>
           </message-driven-descriptor>
          


          In some Application servers like Sun One which will not give that provision to listen in this cases.

          Its always good to look for a general solution like tweaking the jms-ra.rar which is bundled with JBOSS to make it listen to from your Application server to JBOSS MQ.

          The rar comes with a JNDIProvider Adapter which will look for
          java:/DefaultJMSProvider
          some application servers would not accept this naming you can modify 2 classes that comes with the rar to make it work in a generalized way.

          In the package org.jboss.resource.adapter.jms.inflow.JmsActivationSpec bean add the following parameters and also the corresponding methods


           private String providerURL = "jnp://localhost:1099";
           private String initialContextFactory = "org.jnp.interfaces.NamingContextFactory";
           private String urlPkgPrefixes = "org.jnp.interfaces";


          In the package org.jboss.resource.adapter.jms.inflow.JmsActivation bean make the following changes

          protected void setupJMSProviderAdapter() throws Exception
           {
          
           Properties env = new java.util.Properties();
           env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,spec.getInitialContextFactory());
           env.put(javax.naming.Context.PROVIDER_URL,spec.getProviderURL());
           env.put(javax.naming.Context.URL_PKG_PREFIXES,spec.getUrlPkgPrefixes());
           adapter = new org.jboss.jms.jndi.JNDIProviderAdapter();
           adapter.setProperties(env);
           log.debug("Using jms provider adapter " + adapter);
           }


          and in 2 more methods setupTopicConnection and setupQueueConnection make changes to lookup for ConnectionFactory.

          TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");


          while giving the ActiovationSpec in your ejb-jar.xml give the properties in the JmsActiovation spec like:

          <activation-config>
           <activation-config-property>
           <activation-config-property-name>destination</activation-config-property-name>
           <activation-config-property-value>queue/A</activation-config-property-value>
           </activation-config-property>
           <activation-config-property>
           <activation-config-property-name>destinationType</activation-config-property-name>
           <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
           </activation-config-property>
           <activation-config-property>
           <activation-config-property-name>providerURL</activation-config-property-name>
           <activation-config-property-value>jnp://localhost:1099</activation-config-property-value>
           </activation-config-property>
           <activation-config-property>
           <activation-config-property-name>initialContextFactory</activation-config-property-name>
           <activation-config-property-value>org.jnp.interfaces.NamingContextFactory</activation-config-property-value>
           </activation-config-property>
           <activation-config-property>
           <activation-config-property-name>urlPkgPrefixes</activation-config-property-name>
           <activation-config-property-value>org.jnp.interfaces</activation-config-property-value>
           </activation-config-property>
           </activation-config>
          


          you can replace the localhot parameter with the machine ip or the name on which the JBOSS MQ is running .

          Since the rar itself will provide for the JNDI providerAdapter too you need not configure the external JNDI in this case. All you have to do is to point to the rar as an example the sunone

          <sun-ejb-jar>
           <enterprise-beans>
           <ejb>
           <ejb-name>MessageBean</ejb-name>
           <jndi-name>test/myQueue</jndi-name>
           <mdb-resource-adapter>
           <resource-adapter-mid>jms-ra</resource-adapter-mid>
           </mdb-resource-adapter>
           </ejb>
           </enterprise-beans>
          </sun-ejb-jar>
          


          Note: You might want to do away with the DLQ then comment out the call setupDLQ(ctx) in the setup() method of the JmsActiovation.java

          enjoy...

          • 2. Re: JBossMQ under other application servers
            narayanrm

            One more thing I forgot to add if we are actually looking for a remote JBOSS MQ as a naming provider, from 3rd party Application servers, the org.jnp.interfaces.NamingContext.java would call discoverServer(Hashtable serverEnv) method, as commented rightly this would do the following



            /** This methods sends a broadcast message on the network and asks and
            * HA-JNDI server to sent it the HA-JNDI stub
            */


            If we were to circumvent this we can replace the code with

             try{
             String serverHost;
             String providerURL = (String)serverEnv.get("PROVIDER_URL");
             log.info("providerURL is"+providerURL);
             if(providerURL != null){
            
             int schemeLength = 0;
             if( providerURL.startsWith ("java:") )
             schemeLength = 7;
             else if( providerURL.startsWith ("jnp:") )
             schemeLength = 6;
             else if( providerURL.startsWith ("jnps:") )
             schemeLength = 7;
             else if( providerURL.startsWith ("jnp-http:") )
             schemeLength = 11;
             else if( providerURL.startsWith ("jnp-https:") )
             schemeLength = 12;
            
             serverHost = providerURL.substring(schemeLength);
             String[] servers = serverHost.split(":");
             log.info("serverhost is:"+servers[0]+"\n serverPort is "+servers[1]);
             if(servers[0]!= null && servers[1] != null){
             try{
             server = getServer (servers[0], Integer.parseInt(servers[1]), serverEnv);
             }catch(NumberFormatException ne){
             ne.printStackTrace();
             }
             }else
             server = getServer ("localhost", 1099, serverEnv);
             }
             if(server == null)
             server = getServer ("localhost", 1099, serverEnv);
             //}
             return server;
             }
            


            • 3. Re: JBossMQ under other application servers
              disrael

              I am trying to use JBossMQ as a .rar from another application server. With the current jms-ra.rar the first problem I hit is:

              Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/resource/JBossResourceException
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Unknown Source)
              at org.jboss.resource.adapter.jms.JmsManagedConnectionFactory.class$(JmsManagedConnectionFactory.java:45)
              at org.jboss.resource.adapter.jms.JmsManagedConnectionFactory.<clinit>(JmsManagedConnectionFactory.java:45)


              JBossResourceException is not included in the rar file. Thanks very much for the tips below on getting this to work. Are there any plans for JBoss resource adaptor jms-ra.rar to work stand alone? Anyone already done this and published on a web site somewhere?

              Thank you for your help.