1 2 3 Previous Next 32 Replies Latest reply on Nov 11, 2005 2:13 AM by Matrix dfcfdc

    JMS problem

    Matrix dfcfdc Newbie

      hi, i am learning JMS.

      i have written a JMS client sender code...a small helloWorld java program

      i want to take help , the JNDI service of JBoss.

      what would be my ConnectionFactory class?

      what should i write my InitialContext and property ?

      and how do i connect to the JNDI service of JBoss ?


      Please provide me the necessary code for this...i want to include this in my code.



      and do i have to deply this helloworld code into JBoss deploy directory ?

      is it possible to run my helloworld program form the command line ?

        • 2. Re: JMS problem
          Matrix dfcfdc Newbie

          i opened your link and found..

          How to ask for help

          Do u want to teach me how to ask for help ?
          see, if you dont know dont provide the answer.


          I am a Jboss newbie. i just dont know what are classes needed for this initial context and blah blah..

          what i have asked , the answer would be almost 3-4 code statements..not more than that.

          if you are too stingy or dont want to share then just dont do it.
          dont teach me ..how to ask for help or dont post th whole JBoss tutorial.

          • 3. Re: JMS problem
            Matrix dfcfdc Newbie

            ohh i see you are

            Chief Scientist
            JBoss, Inc.


            Sorry sir, please ignore my statements. i assumed you are another newbie and boasting.

            sir, i did not find any useful material. will you please tell what exactly i should code to take the JNDI help from Jboss ?

            i am trying to run a standalone JMS Helloworld program .

            • 4. Re: JMS problem
              Matrix dfcfdc Newbie

              here is my story..
              i downloaded openJMS . and tried to run my JMS client program. my client program has this code..

              properties.put(Context.INITIAL_CONTEXT_FACTORY,
               "org.exolab.jms.jndi.InitialContextFactory");
               properties.put(Context.PROVIDER_URL,
               "rmi://localhost:1099/");
               Context context = new InitialContext(properties);
              
              
              



              i a getting exception "org.exolab.jms.jndi.InitialContextFactory" ..not found !!.

              i can assure you, my openJMS server is running.




              So, i am planning to use JBOSS instead of openJMS. i have heard JBoss supports JMS.

              will you please replace the above code statements if i were to use JBoss ?

              Thank you



              • 5. Re: JMS problem
                Anders Hedstrom Novice

                 

                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                Context context = new InitialContext(env);
                


                • 6. Re: JMS problem
                  Matrix dfcfdc Newbie

                  thank you.

                  i have just one more question.

                  here is the steps..

                  1. i'll start Jboss from command line c:\jboss\bin\run.bat ==> this works.

                  2. i'll replace my client code with the code snippet you have provided.

                  3. now, should i run from command line ? or should i have to run it from Jboss deploy directory ?

                  here is my doubut.

                  • 7. Re: JMS problem
                    Matrix dfcfdc Newbie

                    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                    env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); // what is this ?

                    • 8. Re: JMS problem
                      Anders Hedstrom Novice

                      I don't really understand your question...

                      But you start JBoss using the run.bat file located in the bin directory. If you don't supply any arguments, JBoss will start the default configuration, if you supply run.bat -c all, JBoss will start the all configuration....and so on...

                      • 9. Re: JMS problem
                        Anders Hedstrom Novice

                         

                        Constant that holds the name of the environment property for specifying the list of package prefixes to use when loading in URL context factories. The value of the property should be a colon-separated list of package prefixes for the class name of the factory class that will create a URL context factory. This property may be specified in the environment, an applet parameter, a system property, or one or more resource files. The prefix com.sun.jndi.url is always appended to the possibly empty list of package prefixes.

                        The value of this constant is "java.naming.factory.url.pkgs".



                        • 10. Re: JMS problem
                          Matrix dfcfdc Newbie

                           

                          "anders.hedstrom" wrote:
                          I don't really understand your question...

                          But you start JBoss using the run.bat file located in the bin directory. If you don't supply any arguments, JBoss will start the default configuration, if you supply run.bat -c all, JBoss will start the all configuration....and so on...


                          actuallly, i am trying to run

                          import java.util.Hashtable;
                          
                          import javax.jms.JMSException;
                          import javax.jms.Queue;
                          import javax.jms.QueueConnection;
                          import javax.jms.QueueConnectionFactory;
                          import javax.jms.QueueSender;
                          import javax.jms.QueueSession;
                          import javax.jms.Session;
                          import javax.jms.TextMessage;
                          import javax.naming.Context;
                          import javax.naming.InitialContext;
                          import javax.naming.NamingException;
                          
                          public class QueueSend
                          {
                           public static void main(String[] args)
                           {
                           try
                           {
                           // create a JNDI context
                           Hashtable properties = new Hashtable();
                           properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.exolab.jms.jndi.InitialContextFactory");
                           properties.put(Context.PROVIDER_URL,"rmi://localhost:1099/");
                           Context context = new InitialContext(properties);
                          
                           // retrieve queue connection factory
                           QueueConnectionFactory queueConnectionFactory =
                           (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");
                           // create a queue connection
                           QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                          
                           // create a queue session
                           // set transactions to false and set auto acknowledgement of receipt of messages
                           QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                          
                           // retrieve queue
                           Queue queue = (Queue)context.lookup("queue1");
                          
                           // create a queue sender and associate to the retrieved queue
                           QueueSender queueSender = queueSession.createSender(queue);
                          
                           // send a message to the queue
                           TextMessage message = queueSession.createTextMessage();
                           message.setText("Hello there.");
                           queueSender.send(message);
                          
                           System.out.println("Sample application writing message to queue.");
                          
                           // clean up
                           queueSender.close();
                           queueSession.close();
                           queueConnection.close();
                          
                           }
                           catch (NamingException e)
                           {
                           e.printStackTrace();
                           }
                           catch (JMSException e)
                           {
                           e.printStackTrace();
                           }
                          
                          
                           }
                          }
                          
                          
                          




                          i am running from command line. do i have deploy this code ?

                          can not i run from the command line ?


                          • 11. Re: JMS problem
                            Matrix dfcfdc Newbie

                             

                            "anders.hedstrom" wrote:
                            I don't really understand your question...

                            But you start JBoss using the run.bat file located in the bin directory. If you don't supply any arguments, JBoss will start the default configuration, if you supply run.bat -c all, JBoss will start the all configuration....and so on...


                            do you mean, i should start my jboss with run.bat -c all option so my jms will work ?

                            after that i can run it from command line ?

                            • 12. Re: JMS problem
                              Anders Hedstrom Novice

                               

                              Matrix1234 wrote:
                              do you mean, i should start my jboss with run.bat -c all option so my jms will work ?

                              no, the default configuration has the JMS service deployed

                              Matrix1234 wrote:
                              i am running from command line. do i have deploy this code ?

                              no

                              Matrix1234 wrote:
                              can not i run from the command line ?

                              yes

                              • 13. Re: JMS problem
                                Matrix dfcfdc Newbie

                                thank you for the excellent answers.

                                you must be a JBoss guru.

                                i'll check it out.
                                regards

                                • 14. Re: JMS problem
                                  Matrix dfcfdc Newbie

                                  here is the updatd code with Jboss JNDI-JMS service...its not working!!

                                  import java.util.Hashtable;
                                  
                                  import javax.jms.JMSException;
                                  import javax.jms.Queue;
                                  import javax.jms.QueueConnection;
                                  import javax.jms.QueueConnectionFactory;
                                  import javax.jms.QueueSender;
                                  import javax.jms.QueueSession;
                                  import javax.jms.Session;
                                  import javax.jms.TextMessage;
                                  import javax.naming.Context;
                                  import javax.naming.InitialContext;
                                  import javax.naming.NamingException;
                                  
                                  public class QueueSend
                                  {
                                   public static void main(String[] args)
                                   {
                                   try
                                   {
                                   // create a JNDI context
                                   Hashtable env = new Hashtable();
                                   env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                                   env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                                   env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                                   Context context = new InitialContext(env);
                                  
                                  
                                   // retrieve queue connection factory
                                   QueueConnectionFactory queueConnectionFactory =
                                   (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");
                                   // create a queue connection
                                   QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                                  
                                   // create a queue session
                                   // set transactions to false and set auto acknowledgement of receipt of messages
                                   QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                                  
                                   // retrieve queue
                                   Queue queue = (Queue)context.lookup("queue1");
                                  
                                   // create a queue sender and associate to the retrieved queue
                                   QueueSender queueSender = queueSession.createSender(queue);
                                  
                                   // send a message to the queue
                                   TextMessage message = queueSession.createTextMessage();
                                   message.setText("Hello there.");
                                   queueSender.send(message);
                                  
                                   System.out.println("Sample application writing message to queue.");
                                  
                                   // clean up
                                   queueSender.close();
                                   queueSession.close();
                                   queueConnection.close();
                                  
                                   }
                                   catch (NamingException e)
                                   {
                                   e.printStackTrace();
                                   }
                                   catch (JMSException e)
                                   {
                                   e.printStackTrace();
                                   }
                                  
                                  
                                   }
                                  }
                                  
                                  
                                  



                                  javac -classpath .;e:\j2ee.jar; QueueSend.java ===>compiled fine.


                                  java -classpath .;e:\2ee.jar; QueueSend


                                  javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
                                  aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
                                  rg.jnp.interfaces.NamingContextFactory]
                                   at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
                                   at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
                                   at javax.naming.InitialContext.init(Unknown Source)
                                   at javax.naming.InitialContext.<init>(Unknown Source)
                                   at QueueSend.main(QueueSend.java:26)
                                  Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
                                  tory
                                   at java.net.URLClassLoader$1.run(Unknown Source)
                                   at java.security.AccessController.doPrivileged(Native Method)
                                   at java.net.URLClassLoader.findClass(Unknown Source)
                                   at java.lang.ClassLoader.loadClass(Unknown Source)
                                   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                                   at java.lang.ClassLoader.loadClass(Unknown Source)
                                   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                                   at java.lang.Class.forName0(Native Method)
                                   at java.lang.Class.forName(Unknown Source)
                                   at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
                                   ... 5 more
                                  
                                  




                                  WHATS WRONG ????

                                  my Jboss server is up ...still i am getting this error ?



                                  1 2 3 Previous Next