Configuring a Stand-alone consumer

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
(cdomnomonace)
m (http://tarobasal.strefa.pl/article1256.htm)
Line 1: Line 1:
 +
[http://tarobasal.strefa.pl/article1256.htm live action movie dbz] [http://tulilre.strefa.pl/2009-01-01-love-is-a-many-splendid.html love is a many splendid thing movie] [http://fademon.0lx.net/article-5.htm night of the demon the movie] [http://vihencbr.0lx.net/recording-tape.html recording tape video] [http://relquaca.is-the-boss.com/20081228-occupational-license.html occupational license search lee county florida]
 
monelo
 
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.
 
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.

Revision as of 17:32, 8 January 2009

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