I am trying to run the following client code for JBOSS MQ.

package test;

import java.util.Properties;

import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;


/**
 * @author harishh
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class JMSClient {

        public static void main(String[] args) throws Exception
           {
              log.info("Creating jndi context - alternatively use a 
jndi.properties");
              Properties properties = new Properties();
              properties.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.jnp.interfaces.NamingContextFactory");
              properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
              properties.put(Context.PROVIDER_URL, "localhost");
              InitialContext ctx = new InitialContext(properties);

              log.info("Looking up queue");
              Queue queue = (Queue) ctx.lookup("queue/testQueue");

              log.info("Looking up connection factory");
              QueueConnectionFactory qcf = (QueueConnectionFactory) 
ctx.lookup("UIL2ConnectionFactory");

              log.info("Creating connection");
              QueueConnection qc = qcf.createQueueConnection();
              try
              {
                 log.info("Creating session");
                 QueueSession qs = qc.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
                 
                 log.info("Creating sender");
                 QueueSender sender = qs.createSender(queue);

                 log.info("Creating message");
                 TextMessage message = qs.createTextMessage("hello");

                 log.info("Sending message");
                 sender.send(message);

                 log.info("Creating receiver");
                 QueueReceiver receiver = qs.createReceiver(queue);

                 log.info("Try to receive message, it will not work");
                 Message received = receiver.receiveNoWait();
                 if (received != null)
                    throw new RuntimeException("Maybe you forget to clear the 
queue before running this test?");

                 log.info("You have to start the connection before receiving 
messages");
                 qc.start();

                 log.info("This receive will work");
                 received = receiver.receiveNoWait();

                 log.info("Got message: " + received);
              }
              finally
              {
                 qc.close();
              }
           }

           public static class log
           {
              public static void info(String message)
              {
                 System.out.println(message);
              }
              public static void error(String message, Throwable t)
              {
                 System.err.println(message);
                 t.printStackTrace();
              }
           }
}

I get a class cast exception at the line 

  Queue queue = (Queue) ctx.lookup("queue/testQueue");

My Questions.

1. Where do I set up the queue/testQueue.
2. What configuration is required to run the JBOSSMQ client?Does it require
JNDI configuration or any other configuration?


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3924711#3924711

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3924711


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to