2 Replies Latest reply on Apr 28, 2008 9:22 AM by nitinmandolkar

    Creating New Connection Factory

    nitinmandolkar

      Hi All

      The default connection factory name in jbos is ConnectionFactoty, java:/ConnectionFactory, XAConnectionFactory and java:/XAConnectionFactory.

      So when ever i need to connect JBOSS JMS Server my client code need to look for above name in JNDI. Sample code below...

      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("java:/ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;

      With above code block my example is working fine with out any problem.

      Due to old code base i can not use default Connection factory name provided by JBOSS. I am intrest to give my name to connection factory. So in search of that i did some change in jms-ds.xml as below.
      <!--

      DefaultJMSProvider

      org.jboss.jms.jndi.JNDIProviderAdapter

      <!-- The combined connection factory -->
      java:/MyConnectionFactory
      <!-- The queue connection factory -->
      java:/MyConnectionFactory
      <!-- The topic factory -->
      java:/MyConnectionFactory
      <!-- Uncomment to use HAJNDI to access JMS

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost:1100

      -->

      -->
      After doing this change in jms-ds.xml file i change the above code block like this. Now i am looking for "MYConnectionFactory" rather than "ConnectionFactory".

      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("java:/MyConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;

      Doing this change i am excepting it shoud work. but i am getting following error. Can one tell me where i can define new connection factory in JBOSS 4.2.2 GA and how.

      Exception i am getting :
      ====================
      run-example1p2p:
      [java] [INFO,SendRecvClient] Begin SendRecvClient, now=1209322015968
      [java] [INFO,SendRecvClient] Begin sendRecvAsync
      [java] Exception in thread "main" javax.naming.NameNotFoundException: MyCon
      nectionFactory not bound
      [java] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)

      [java] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)

      [java] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      [java] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
      sorImpl.java:39)
      [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
      hodAccessorImpl.java:25)
      [java] at java.lang.reflect.Method.invoke(Method.java:585)
      [java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.jav
      a:294)
      [java] at sun.rmi.transport.Transport$1.run(Transport.java:153)
      [java] at java.security.AccessController.doPrivileged(Native Method)
      [java] at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      [java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTranspor
      t.java:466)
      [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPT
      ransport.java:707)
      [java] at java.lang.Thread.run(Thread.java:595)
      [java] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServe
      r(StreamRemoteCall.java:247)
      [java] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCa
      ll.java:223)
      [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
      [java] at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:66
      7)
      [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:62
      7)
      [java] at javax.naming.InitialContext.lookup(InitialContext.java:351)
      [java] at org.jboss.book.jms.ex1.SendRecvClient.setupPTP(SendRecvClient
      .java:56)
      [java] at org.jboss.book.jms.ex1.SendRecvClient.sendRecvAsync(SendRecvC
      lient.java:72)
      [java] at org.jboss.book.jms.ex1.SendRecvClient.main(SendRecvClient.jav
      a:104)
      [java] Java Result: 1

        • 1. Re: Creating New Connection Factory
          kahzoo

           

          Can one tell me where i can define new connection factory in JBOSS 4.2.2 GA and how.


          This depends on where your client code runs. If it runs in the same JVM as the JBoss server, you need to modiy

          deploy/jms/jvm-il-service.xml

          Otherwise (when your client runs remotely from the JBoss server),

          deploy/jms/uil2-service.xml

          Either way, if all you want to do is to change the name of the connection factory. you simply change the value of '(XA)ConnectionFactoryJNDIRef' attributes.

          If you want to add a new name to an existing connecion factory, you may want to use NamingAlias bean. You can find an example of this in deploy/jms/uil2-service.xml as below.

          <mbean code="org.jboss.naming.NamingAlias" name="jboss.mq:service=InvocationLayer,type=UIL">
           <attribute name="FromName">UILConnectionFactory</attribute>
           <attribute name="ToName">ConnectionFactory</attribute>
           <depends>jboss:service=Naming</depends>
           </mbean>
          
          


          Hope this helps.


          • 2. Re: Creating New Connection Factory
            nitinmandolkar

            Thanks a lot. It works.