14 Replies Latest reply on Sep 16, 2003 1:32 AM by stephanenicoll

    Help deploying my first JMS program

    garandi

      How to deploy JMS program, in JBoss?
      I have written a small JMS program, but when I want to run it a get the following error.

      org.jboss.mq.SpyJMSException: Cannot get the Queue from the provider; - nested throwable: (javax.jms.JMSException: This destination does not exist !)


      Although I am using the default Queue.

      Queue q = qs.createQueue("queue/testQueue");

      Do I have to deploy my app some how? I am using JBoss 4.
      Do I have to change some xml file if yes which one and where?

      Thank you in advance
      Garandi

        • 1. Re: Help deploying my first JMS program

          That is the jndi name, you should look it up.

          Regards,
          Adrian

          • 2. Re: Help deploying my first JMS program
            garandi

            Thank you, but could you please tell me how to look it up?

            I have set up the following mbean in user-service.xml file.
            QueueSenderExample.java is in the jmsexample package and the path is
            c:\jmsexample.QueueSenderExample.java



            queue/JawadQueue
            5150
            2048
            C:\\JBossLog\\
            queue/MyQueue
            java:/ConnectionFactory
            jboss.mq:service=DestinationManager
            jboss.mq:service=InvocationLayer,type=JVM
            jboss.mq.destination:service=Queue,name=JawadQueue
            True


            but when I start JBoss I get NullPointerException. In the server console.


            13:42:19,554 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss
            -4.0.0DR2/server/default/deploy/user-service.xml
            13:42:19,585 WARN [ServiceController] Problem creating service jboss.deployment
            :name=file%3a/C%3a/jboss-4.0.0DR2/server/default/deploy/user-service.xml,service
            =DeploymentInfo
            org.jboss.deployment.DeploymentException: create operation failed for package fi
            le:/C:/jboss-4.0.0DR2/server/default/deploy/user-service.xml; - nested throwable
            : (java.lang.NullPointerException)
            at org.jboss.deployment.SARDeployer.create(SARDeployer.java:202)
            at org.jboss.deployment.DeploymentInfo.create(DeploymentInfo.java:243)
            at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
            sorImpl.java:25)


            Thank you for your help so far.
            Garandi

            • 3. Re: Help deploying my first JMS program
              nphelps

              Context context = new InitialContext();
              QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
              Queue queue = (Queue)context.lookup("queue/testQueue");
              etc..

              • 4. Re: Help deploying my first JMS program
                garandi

                What dir. under JBoss should I copy myApp.class file?
                Thank you in advance.
                Garandi

                • 5. Re: Help deploying my first JMS program

                  Woh oh, you're definetly missing something here :) I think that you should have a look to the free Jboss documentation and study all this a little bit.

                  FYI, application are always packaged in some ways:

                  - a jar file containing EJBs
                  - a war file containing a web application
                  - a sar file containing services - MBeans
                  - an ear file containing a mix of those

                  Each application has always a deployment descriptor. So even if you have an test MDB that test JMS somehow you have to put it deployment description, packaged in a JAR file. Then it's put in the deploy directory of the server which is started (normally $JBOSS_HOME/server/default/deploy)

                  My suggesstion, read the free jboss doco and have a look to XDoclet and Ant which are two free tools very usefull to start with.

                  Regards,

                  Stephane

                  • 6. Re: Help deploying my first JMS program
                    garandi

                    Thank you for your reply Stephane.
                    I have only one week to deploy a JMS application. I am reading JMS book and some notes and don't have problem understanding the concept. But so far my biggest problem is the concept of "mbean", how to write my user-serive.xml file and deploying my application. I read the documentation but just one or two page was about JMS and in there it did NOT explain how to write user-service.xml file or how to deploy it.
                    Could you please explain if you have time the tages in user-service.xml file and how to deploy an jms app?
                    Thank you in advance
                    Garandi

                    • 7. Re: Help deploying my first JMS program

                      Yes, I can do that.

                      What kind of MBean are you trying to deploy? Are you trying to create a new JMS queue?

                      Regards,

                      Stephane

                      • 8. Re: Help deploying my first JMS program
                        garandi

                        Stephane,
                        Thank you very much for your help so far.
                        I am using "testQueue" which comes with jboss.
                        my user-service.xml file looks like this, and it is in
                        c:\JBOSS_HOME\server\all\deploy\user-service.xml and when I start jboss, I use the command "run -c all".

                        That is how my user-service.xml looks like.



                        mbean code="org.jboss.mq.server.QueueManager"
                        name="user:service=QueueSenderExample" name="user.service=QueueReceiverExample">
                        5150
                        2048
                        C:\\JBossLog
                        queue/testQeueu
                        java:/ConnectionFactory
                        True
                        jboss.mq:service=DestinationManager
                        jboss.mq:service=InvocationLayer,type=JVM
                        jboss.mq.destination:service=Queue,name=testQueue




                        Sender code is:


                        public void ptpMessageSender(String factoryJNDI, String queueJNDI) throws NamingException, JMSException{
                        System.out.println("Enter the sender method");
                        //Create queue connection
                        InitialContext ic = new InitialContext();
                        QueueConnectionFactory qcf = (QueueConnectionFactory)ic.lookup(factoryJNDI);
                        QueueConnection qc = qcf.createQueueConnection();
                        qc.start();

                        // Create Session
                        QueueSession qs = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
                        Queue q = qs.createQueue(queueJNDI);

                        // Create Messge using session object


                        TextMessage sMsg = qs.createTextMessage();
                        sMsg.setText("This is the first msg.");

                        //Create a queue sender
                        QueueSender qSender = qs.createSender(q);
                        qSender.send(sMsg);
                        qSender.setTimeToLive(10000000);
                        System.out.println("The msg was send");
                        //Cleaning up
                        qc.close();
                        }



                        and receiver code is:


                        public class QueueReceiverExample {
                        public void ptpMessageReceiver(String factoryJNDI, String queueJNDI) throws NamingException, JMSException{
                        System.out.println("Enter the receiver method");
                        //Create queue connection
                        InitialContext ic = new InitialContext();
                        QueueConnectionFactory qcf = (QueueConnectionFactory)ic.lookup(factoryJNDI);
                        QueueConnection qc = qcf.createQueueConnection();
                        qc.start();

                        // Create Session
                        QueueSession qs = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
                        Queue q = qs.createQueue(queueJNDI);
                        System.out.println("The session is created");
                        //Create a queue receiver
                        QueueReceiver qReceiver = qs.createReceiver(q);
                        System.out.println("The receiver was created");
                        TextMessage msg =(TextMessage) qReceiver.receive();
                        System.out.println("Received the message ...");
                        String m = msg.getText();
                        System.out.println("and the message is--->"+ m);

                        qc.close();

                        }

                        public static void main(String[] argc){
                        QueueReceiverExample e = new QueueReceiverExample();
                        try{
                        e.ptpMessageReceiver("ConnectionFactory", "testQueue");
                        }
                        catch(NamingException ne){
                        ne.printStackTrace();
                        }
                        catch(JMSException jmse){
                        jmse.printStackTrace();
                        System.out.println(jmse.getCause().getMessage());
                        }
                        }

                        }


                        the code is in "jmsexample" package and the path for the code is
                        c:\jmsexample\QueueReceiverExample
                        c:\jmsexample\QueueSenderExample

                        the problem is it blocks on

                        TextMessage msg =(TextMessage) qReceiver.receive();

                        Thank you in advance.
                        Garandi

                        • 9. Re: Help deploying my first JMS program

                          Well ...

                          1/ Is there any reson why you should use JBoss4. It's a developper release. In any case it should be used for production or anything else. Public release is 3.2.1. Start with installing that version

                          2/ your user-service.xml is completely 'useless". I mean, if you are using testQueue, you don't need to define something else. If you want to define your own queue, I already posted a sample.

                          The code snipet seems ok to me

                          In queue receiver replace the receive() call to this

                          Message msg = qReceiver.receiveNoWait();
                          if (msg == null)
                          System.out.println("No message in the queue");
                          else {
                          // will fail if the message is not a TextMessage
                          TextMessage txtMsg = (TextMessage) msg;
                          System.out.println(txtMsg.getText());
                          }

                          I thing receive() is blocked cause you are not able to send a message to the queue. So, since the queue is empty, the method does not return.

                          When you invoke queuesenderexample, is it working?

                          Do not forget to add some jar in the classpath of your client (jboss-j2ee.jar, jbossall-client.jar)

                          Regards,

                          Stephane

                          • 10. Re: Help deploying my first JMS program

                            Seems i posted the definition in another thread :)

                            If you want to create the queue yourQueue, do the following


                            <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager

                            • 11. Re: Help deploying my first JMS program
                              garandi

                              Stephane, thank you for your reply so far.
                              QueueSenderExample.java is working fine.
                              I fixed the problem, after creating the receiver I did the following.

                              receiver.setMessageListener(new MessageListener(){
                              public void onMessage(Message msg){
                              TextMessage tm = (TextMessage) msg;
                              try{
                              tm.getText();
                              }
                              catch(JMSException e){
                              e.printStackTrace();
                              }

                              }
                              }););

                              and that fix the problem.
                              Thank you very much for all the helps.
                              Garandi

                              • 12. Re: Help deploying my first JMS program

                                Yeah, I just saw in the meantime that you created a transactionnal JMS session without calling jmsSession.commit(); after having sent the msg.

                                This might be the problem. Create your session with false instead of true (or at least commit(); after having sent your message)

                                Regards,

                                Stephane

                                • 13. Re: Help deploying my first JMS program
                                  garandi

                                  Stephane,
                                  Thanks for all your help, changing true to false in connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

                                  fixed the problem.
                                  Thank you
                                  Garandi

                                  • 14. Re: Help deploying my first JMS program

                                    Great!

                                    Regards,

                                    Stephane