11 Replies Latest reply on Feb 23, 2004 10:11 PM by jamlu

    How Can I get a ConnectionFactory using JMS with JBoss?

    Kobye Novice

      HI.Thank you .
      this time I am in another trouble.
      How to get a ConnectionFactory?
      In the jboss_home/server/default/deploy/jms/ directory,there is a file named jms-ds.xml, there is a tag named <connection-factories>, and a tag named " "
      .
      Is this a ConnectionFactory JNDI name?
      who can tell me?
      Thak you .

        • 1. Re: How Can I get a ConnectionFactory using JMS with JBoss?
          Kobye Novice

          My code is below:

          try {
          java.util.Hashtable JNDIParm = new java.util.Hashtable();
          JNDIParm.put(Context.PROVIDER_URL, "localhost");
          JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          jndiContext = new InitialContext(JNDIParm);
          } catch (NamingException e) {
          System.out.println("Could not create JNDI API " +
          "context: " + e.toString());
          System.exit(1);
          }
          try {
          queueConnectionFactory = (QueueConnectionFactory)
          jndiContext.lookup("JBossMQProvider");
          queue = (Queue) jndiContext.lookup(queueName);
          } catch (NamingException e) {
          System.out.println("JNDI API lookup failed: " +
          e.toString());
          System.exit(1);
          }

          • 2. Re: How Can I get a ConnectionFactory using JMS with JBoss?
            Kobye Novice

            JBossMQProvider
            when my program run, it throws an exception,
            JNDI API lookup failed: javax.naming.NameNotFoundException: JBossMQProvider not bound

            who can Help?
            thank you

            • 3. Re: How Can I get a ConnectionFactory using JMS with JBoss?
              Adrian Brock Master

              lookup UIL2ConnectionFactory

              Regards,
              Adrian

              • 4. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                Kobye Novice

                the result of look UIL2ConnectionFactory is

                JNDI API lookup failed: javax.naming.NameNotFoundException: UIL2ConnectionFactory not bound.
                Maybe I think the JNDI name is in a file?
                but I can't fiind it.

                • 5. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                  Adrian Brock Master

                  Which version of JBoss are you using?
                  Have you tried the getting started docs?

                  Try lookup "ConnectionFactory", if that doesn't work, you aren't connecting to jboss's jndi

                  Regards,
                  Adrian

                  • 6. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                    Kobye Novice

                    to Adrian:
                    I run my program while JBoss is running.
                    but it still does not work.
                    Follow is JNDIContext:
                    java.util.Hashtable JNDIParm = new java.util.Hashtable();
                    JNDIParm.put(Context.PROVIDER_URL, "localhost");
                    JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                    jndiContext = new InitialContext(JNDIParm);
                    when I use it to look up EntityBean,it runs well.

                    • 7. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                      Kobye Novice

                      package simple;
                      import javax.jms.*;
                      import javax.naming.*;

                      public class SimpleQueueReceiver {
                      public static void main(String[] args) {
                      String queueName = "A";
                      Context jndiContext = null;
                      QueueConnectionFactory queueConnectionFactory = null;
                      QueueConnection queueConnection = null;
                      QueueSession queueSession = null;
                      Queue queue = null;
                      QueueReceiver queueReceiver = null;
                      TextMessage message = null;
                      System.out.println("Queue name is " + queueName);
                      try {
                      // jndiContext = new InitialContext();
                      java.util.Hashtable JNDIParm = new java.util.Hashtable();
                      JNDIParm.put(Context.PROVIDER_URL, "localhost");
                      JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                      jndiContext = new InitialContext(JNDIParm);

                      queueConnectionFactory = (QueueConnectionFactory)
                      jndiContext.lookup("ConnectionFactory ");
                      queue = (Queue) jndiContext.lookup(queueName);

                      queueConnection =
                      queueConnectionFactory.createQueueConnection();
                      queueSession =
                      queueConnection.createQueueSession(false,
                      Session.AUTO_ACKNOWLEDGE);
                      queueReceiver = queueSession.createReceiver(queue);
                      queueConnection.start();
                      while (true) {
                      Message m = queueReceiver.receive(1);
                      if (m != null) {
                      if (m instanceof TextMessage) {
                      message = (TextMessage) m;
                      System.out.println("Reading message: " +
                      message.getText());
                      } else {
                      break;
                      }
                      }
                      }
                      } catch (Exception e) {
                      e.printStackTrace();
                      } finally {
                      if (queueConnection != null) {
                      try {
                      queueConnection.close();
                      } catch (JMSException e) {}
                      }
                      }
                      }
                      }

                      • 8. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                        Kobye Novice

                        Up is my JMS reciever. I known there is a default Queue named "A".But How can I get ConnectionFactory?Is there a JNDI name I can use and what is it?

                        • 9. 3739954
                          Kobye Novice

                          Queue name is A

                          javax.naming.NameNotFoundException: ConnectionFactory not bound

                          at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)

                          at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)

                          at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)

                          at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:528)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)

                          at javax.naming.InitialContext.lookup(InitialContext.java:350)

                          at simple.SimpleQueueReceiver.main(SimpleQueueReceiver.java:69)



                          This is the error message when it runs.

                          • 10. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                            Kobye Novice

                            Thank you,everyone.
                            The problem has resovled.

                            • 11. Re: How Can I get a ConnectionFactory using JMS with JBoss?
                              jamlu Newbie

                              hi:
                              I am an Chinese boy!
                              Can you share your experiences with me? thanks a lot!
                              My MSN:javailoveyou@hotmail.com.