Configuring a Stand-alone consumer

From Resin 3.0

Revision as of 07:50, 9 January 2009 by Eltc4Tdoma (Talk | contribs)
Jump to: navigation, search

norton antivirus 2004 serials kari movie wuhrer illinois joppa movie theater http joblo.com present the 50 coolest movie of all time anal gallery movie teen masala movies portable dvd movie player leisure suit larry trial expired crack photograph video code live action movie dbz love is a many splendid thing movie night of the demon the movie recording tape video occupational license search lee county florida monelo Note: this does not work yet, any help would be greatly appreciated! My goal is to have a nice php form submit jobs to a queue and have a standalone java application respond.


when i run this app, here is the output:

  1. >java SimpleConsumer jms/Queue

Destination name is jms/Queue Progress JNDI API lookup failed: java.lang.NullPointerException

So that tells me it makes it to the lookup of the jms/ConnectionFactory item.

SimpleConsumer.java:



import javax.jms.*; import javax.naming.*; import java.util.Hashtable;


public class SimpleConsumer {

   public static void main(String[] args) {
       String destName = null;
       Context jndiContext = null;
       ConnectionFactory connectionFactory = null;
       Connection connection = null;
       Session session = null;
       Destination dest = null;
       MessageConsumer consumer = null;
       TextMessage message = null;
       if (args.length != 1) {
           System.out.println("java SimpleConsumer: dest_name");
           System.exit(1);
       }
       destName = new String(args[0]);
       System.out.println("Destination name is " + destName);

// Properties env = new Properties( );

       Hashtable env = new Hashtable();
       //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.caucho.jms.ConnectionFactoryImpl");
       env.put(Context.INITIAL_CONTEXT_FACTORY, "com.caucho.naming.InitialContextFactoryImpl");
       env.put(Context.URL_PKG_PREFIXES, "com.caucho.naming");
       // ... specify the JNDI properties specific to the vendor


       try {
               InitialContext jndi = new InitialContext(env);
           //jndiContext = new InitialContext(env);
       } catch (NamingException e) {
           System.out.println("Could not create JNDI API context: " +
               e.toString());
           System.exit(1);
       }
       System.out.println("Progress");
       try {
           connectionFactory = (ConnectionFactory) jndiContext.lookup(
                   "jms/ConnectionFactory");
       System.out.println("more Progress");
           dest = (Destination) jndiContext.lookup(destName);
       } catch (Exception e) {
           System.out.println("JNDI API lookup failed: " + e.toString());
           System.exit(1);
       }
       try {
    connection = connectionFactory.createConnection();
           session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
           consumer = session.createConsumer(dest);
           connection.start();
           while (true) {
               Message m = consumer.receive(1);
               if (m != null) {
                   if (m instanceof TextMessage) {
                       message = (TextMessage) m;
                       System.out.println("Reading message: " +
                           message.getText());
                   } else {
                       break;
                   }
               }
           }
       } catch (JMSException e) {
           System.out.println("Exception occurred: " + e.toString());
       } finally {
           if (connection != null) {
               try {
                   connection.close();
               } catch (JMSException e) {
               }
           }
       }
   }

}

Personal tools