3 Replies Latest reply on Feb 12, 2009 1:18 AM by gaohoward

    JNDI lookup failed for QueueSender program

    siddharth_2279

      Hi All,

      I am trying for a simple Queue Sender and receiver JBoss messaging program. I am using JBoss-5.0.0 G.A. application server. I am getting the following exception while running the program.


      ]JNDI lookup failed: javax.naming.NameNotFoundException: QueueConnectionFactory not bound

      public static void main(String[] args) {
       // TODO Auto-generated method stub
       String queueName = null;
       Context jndiContext = null;
       QueueConnectionFactory queueConnectionFactory = null;
       QueueConnection queueConnection = null;
       QueueSession queueSession = null;
       Queue queue = null;
       QueueSender queueSender = null;
       TextMessage message = null;
      
       final int NUM_MSGS;
      
       if ((args.length < 1) || (args.length > 2)) {
       System.out.println("Usage: java SimpleQueueSender "
       + "<queue-name> [<number-of-messages>]");
       System.exit(1);
       }
      
       queueName = new String(args[0]);
       System.out.println("Queue Name Is : " + queueName);
      
       if (args.length == 2) {
       NUM_MSGS = (new Integer(args[1])).intValue();
       } else {
       NUM_MSGS = 1;
       }
      
       Properties props = new Properties();
       props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       props.put("java.naming.provider.url", "localhost:1099");
      
       try {
       jndiContext = new InitialContext(props);
       } catch (NamingException e) {
       System.out.println("Could not create JNDI " + "context: "
       + e.toString());
       System.exit(1);
       }
      
       try {
       queueConnectionFactory = (QueueConnectionFactory) jndiContext
       .lookup("QueueConnectionFactory");
       queue = (Queue) jndiContext.lookup("queue/"+queueName);
       } catch (NamingException e) {
       System.out.println("JNDI lookup failed: " + e.toString());
       System.exit(1);
       }
      
       try {
       queueConnection = queueConnectionFactory.createQueueConnection();
       queueSession = queueConnection.createQueueSession(false,
       Session.AUTO_ACKNOWLEDGE);
       queueSender = queueSession.createSender(queue);
       message = queueSession.createTextMessage();
      
       for (int i = 0; i < NUM_MSGS; i++) {
       message.setText("This is message " + (i + 1));
       System.out.println("Sending Message: " + message.getText());
       queueSender.send(message);
       }
       queueSender.send(queueSession.createMessage());
       } catch (JMSException e) {
       System.out.println("Exception occurred: " + e.toString());
       } finally {
       if (queueConnection != null) {
       try {
       queueConnection.close();
       } catch (JMSException e) {
       System.out.println("Exception occurred: " + e.toString());
       }
       }
       }
      
       }



      Dosen't JBoss-5.0.0. G.A. application server gives a default QueueConnectionFactory and a default TopicConnectionFactory as in JBoss-4.2.2 GA.? Do we have to create a QueueConnectionFactory and TopicConnectionFactory by ourselves. If yes, then where do we create it - in jboss-5.0.0.GA\server\default\deploy\messaging\destinations-service.xml.

      Please do guide me as I am not able to proceed further. Thanks in advance.

        • 1. Re: JNDI lookup failed for QueueSender program
          gaohoward

          you should look for connection-factories-service.xml, this file can configure JNDI name mappings for a connection factory. The default names are:

          /ConnectionFactory
          /XAConnectionFactory

          So you can try to look up using one of them, like:

          queueConnectionFactory = (QueueConnectionFactory) jndiContext
          .lookup("/ConnectionFactory");

          • 2. Re: JNDI lookup failed for QueueSender program
            siddharth_2279

            Hi,

            Thanks for the prompt reply.

            you should look for connection-factories-service.xml, this file can configure JNDI name mappings for a connection factory. The default names are:

            /ConnectionFactory
            /XAConnectionFactory


            Q 1. What do we mean by /XAConnectionFactory. ?

            Q 2. If I want to make my own connection factory (for e.g. QueueConnectionFactory OR TopicConnectionFactory) then what do I do?

            Q 3. If I want to make my own ConnectionFactory with a clientID lets say for durable connection then what steps do I need to take ?

            Please guide me. Thanks in advance.


            • 3. Re: JNDI lookup failed for QueueSender program
              gaohoward

              Hi,

              /XAConnectionFactory is one of the JNDIBindings in the connection-factory-service.xml. Take a look at this file, you will use it to configure your own Connection factory. It also gives samples on how to configure a connection factory like clientID.