6 Replies Latest reply on Apr 25, 2005 12:56 PM by kirillp

    How to create new ConnectionFactories in JBoss 4.0

    amahesh

      Hi,

      I am trying to send a message to a queue in JBoss 4.0 from a Stateless Session bean. I have implemented a MDB to receive messages from that queue. However, even though no compilation/runtimes errors show up, I am not able to receive the message. I have put debug statements in ejbCreate() and setMessageDrivenContext() as well, but they are also not showing up. I have made the necessary entry into ejb-jar.xml and jboss.xml for this MDB as well. The MDB and the queue are also bounded by the App server.

      I am using the default ConnectionFactory provided with JBoss (context.lookup("ConnectionFactory")) and I receive an object of SpyConnectionFactory. However, I somehow have a feel that my connection factory is not properly setup and /or linked to my queue. Becoz of this, neither does my message go to the queue (but why dont I get any exception then ???) and consequently my MBD doesn't get instantiated and hence no message is received.

      Can anyone help me out with this problem. Can anyone mention detailed steps (with example, if possible) for creating a new QueueConnectionFactory in JBoss 4.0 and associating my queue with it.

      Sir, Please let me know if you need any more information from my side for replying to this query.

      Thanks a Lot, in advance,
      Amit.

        • 1. Re: How to create new ConnectionFactories in JBoss 4.0
          anil.saldhana

          Amit,
          have u created a queue for the MDB to listen to?

          Assuming u have deployed a Queue with a JNDI name as queue/myQueue, you need to associate the MDB with the queue in your jboss.xml file as follows:

          <message-driven>
           <ejb-name>Amit'sMDB</ejb-name>
           <destination-jndi-name>queue/myQueue</destination-jndi-name>
           </message-driven>
          


          Now if you want to create a queue, you can have a xxx-service.xml in your deploy directory with the following:
          <server>
           <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=myQueue">
           <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
           </mbean>
          </server>
          


          I suspect from ur original description, ur MDB is not listening to a JMS queue. Look for tutorials on deploying MDBs in JBoss for further information.

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

          • 2. Re: How to create new ConnectionFactories in JBoss 4.0
            amahesh

            Thanks Anil, for responding back.

            However, I have already added my Queue to jbossmq-destinations-service.xml file under the <JBOSS_DIR>\server\default\deploy\jms folder. At startup, my JBoss shows up a debug statement "Amit_Queue bound". (I had mentioned this in my initial prob desc as well.). I had also been to the site mentioned by you, but it does not solve my problems.

            I have also mentioned the MDB name and its associated Queue in jBoss.xml. (see below)

            However, still I was unable to receive the message.

            Is there a way in JBoss, that I can come to know whether my Producer appln (Stateless SB on JBoss) is actually able to send messages, or it is simply fooling me by not sending messages and also not throwing any exceptions on screen as well....

            I think there is something more to it than meets the eye...maybe some other config which I am missing....Well this is all that I have done..

            a) Created a MDB (InformerBean)

            b) Added config data to ejb-jar.xml

             <message-driven >
             <description>[CDATA[Description for Informer]]</description>
             <display-name>Name for Informer</display-name>
            
             <ejb-name>InformerBean</ejb-name>
            
             <ejb-class>com.amit.msgdb.InformerBean</ejb-class>
            
             <transaction-type>Container</transaction-type>
             <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
             <message-driven-destination>
             <destination-type>javax.jms.Queue</destination-type>
             <!-- <subscription-durability>Durable</subscription-durability> -->
             </message-driven-destination>
            
             <resource-ref>
             <res-ref-name>jms/ConnectionFactory</res-ref-name>
             <res-type>javax.jms.QueueConnectionFactory</res-type>
             <res-auth>Container</res-auth>
             </resource-ref>
            
            
             </message-driven>
            


            c) Added config to JBoss.xml

             <message-driven>
             <ejb-name>InformerBean</ejb-name>
             <destination-jndi-name>queue/Amit_Queue</destination-jndi-name>
             <resource-ref>
             <res-ref-name>jms/ConnectionFactory</res-ref-name>
             <jndi-name>XAConnectionFactory</jndi-name>
             </resource-ref> </message-driven>
            


            d) Added the queue name to jbossmq-destinations-service.xml:

            <mbeancode ="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=Amitz_Queue"> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends></mbean>
            


            e) Added a login-config.xml to META-INF folder adding the following contents:

            <application-policy name = "AMITZJmsXARealm">
             <authentication>
             <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
             flag = "required">
             <module-option name = "principal">guest</module-option>
             <module-option name = "userName">guest</module-option>
             <module-option name = "password">guest</module-option>
             <module-option name = "managedConnectionFactoryName">jboss.jca:service=TxCM,name=DefaultJMSProvider</module-option>
             </login-module>
             </authentication>
            </application-policy>
            


            f) Added the config for "AMITZJmsXARealm" in jms-ds.xml:

            <tx-connection-factory>
             <jndi-name>DefaultJMSProvider</jndi-name>
             <xa-transaction/>
             <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:/DefaultJMSProvider</config-property>
             <security-domain-and-application>AMITZJmsXARealm</security-domain-and-application>
             </tx-connection-factory>
            


            The steps e and f were added after the steps a to d did not give the required results.

            Can you help me now ? I will be obliged.

            Thanks a ton !!

            Regards,
            Amit.




            • 3. Re: How to create new ConnectionFactories in JBoss 4.0

              Amit_Queue != Amitz_Queue

              • 4. Re: How to create new ConnectionFactories in JBoss 4.0
                amahesh

                Hi adrian,

                Thanks for pointing out the error that I gave in the XML data in here. But this was actually a typo in the XML file that I had given here...I have rechecked, and the queue name IS actually Amit_Queue instead of Amitz_Queue.

                Still my problem isn't solved...

                I am also attaching the code from my Stateless Ses Bean, which I am using to send a message to be eventually caught by the MDB...

                This code is written in setSessionContext() method:

                qcFact = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                System.out.println("Uselessly Found the queue Factory :" + qcFact.toString());
                
                queue = (Queue)context.lookup("queue/Amit_Queue");
                System.out.println("Got the Queue :" + queue);

                The following code (Producing a message) is written in business method of that SSB:

                QueueConnection qCon = qcFact.createQueueConnection();
                 QueueSession qSess = qCon.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
                 QueueSender qSender = qSess.createSender(queue);
                
                 String msg = "An employee with name = ** " + naam + " " + prop +
                 " has been created with an employee id = " + Integer.toString(num);
                 TextMessage tm = qSess.createTextMessage();
                 tm.setText(msg);
                
                 qSender.send(tm);
                 System.out.println("SENT THE MESSAGE to Test Q!");
                 qSender.close();
                 qCon.close();

                Here are the debug statements that I am gtting from the server:

                16:08:58,046 INFO [Amit_Queue] Bound to JNDI name: queue/Amit_Queue
                ........
                ........
                16:19:17,312 INFO [STDOUT] Uselessly Found the queue Factory :org.jboss.mq.SpyConnectionFactory@1d4894c
                16:19:17,328 INFO [STDOUT] Got the Queue :QUEUE.Amit_Queue
                16:19:17,328 INFO [STDOUT] Creating the Stateless Bean
                16:19:17,390 INFO [STDOUT] SENT THE MESSAGE to Test Q!


                I have put a debug statement in my MDB's setMessageDrivenContext() as well as at entry point of onMessage() method, but none of them show up.

                Any help is gladly welcome....

                Else, can anyone provide me a new and fresh setup in entirety (code, config files etc), in which a SSB gives a message to a Queue(a user's queue, not the ones delivered with JBOss), and the MBD receives it successfully....

                Looking forward for help.

                Thanks,
                Amit.

                • 5. Re: How to create new ConnectionFactories in JBoss 4.0
                  amahesh

                  In the server's output that I had pasted in my previous mail, I forgot to paste a few lines which might be helpful/informative :

                  The output from the server is:

                  16:08:58,046 INFO [Amit_Queue] Bound to JNDI name: queue/Amit_Queue
                  ....
                  16:09:15,312 INFO [EjbModule] Deploying InformerBean
                  16:09:19,218 WARN [StatelessSessionContainer] No resource manager found for jms/ConnectionFactory
                  16:09:19,218 WARN [StatelessSessionContainer] No resource manager found for jms/Queue
                  ....
                  16:19:17,312 INFO [STDOUT] Uselessly Found the queue Factory :org.jboss.mq.SpyConnectionFactory@1d4894c
                  16:19:17,328 INFO [STDOUT] Got the Queue :QUEUE.Amit_Queue
                  16:19:17,328 INFO [STDOUT] Creating the Stateless Bean
                  16:19:17,390 INFO [STDOUT] SENT THE MESSAGE to Test Q!


                  Hope this helps.

                  But Why are the resource managers not being found ?????

                  Thanks,
                  Amit.

                  • 6. Re: How to create new ConnectionFactories in JBoss 4.0
                    kirillp

                    I have the exact same problems...

                    Any solutions?