/* * Created on Dec 9, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package wbitest; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.Session; import javax.jms.TextMessage; /** * @author Headley Williamson * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public class QueueIBMTest { static String INITIAL_CONTEXT_FACTORY = "com.ibm.websphere.naming.WsnInitialContextFactory"; static String PROVIDER_URL = "iiop://localhost:2809/"; static String connectionFactoryJNDIname = "jms/headleyCF"; static String queueJNDIname = "jms/headleyq"; public static void main(String[] args) throws Exception { java.util.Hashtable env = new java.util.Hashtable(); env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); env.put(javax.naming.Context.PROVIDER_URL, PROVIDER_URL); javax.naming.Context ctx = new javax.naming.InitialContext(env); QueueConnectionFactory factory = (QueueConnectionFactory) ctx .lookup(connectionFactoryJNDIname); Queue ioQueue = (Queue) ctx.lookup(queueJNDIname); QueueConnection connection = factory.createQueueConnection(); connection.start(); boolean transacted = false; QueueSession session = connection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE); QueueSender queueSender = session.createSender(ioQueue); // The session is used to create messages, so create an empty // TextMessage and fill it with some data System.out.println( "Creating a TextMessage" ); TextMessage outMessage = session.createTextMessage(); System.out.println("Adding Text"); outMessage.setText("Are we having fun yet?"); // Ask the QueueSender to send the message we have created System.out.println( "Sending the message to " + ioQueue.getQueueName() ); queueSender.send(outMessage); // Closing QueueSender System.out.println("Closing QueueSender"); queueSender.close(); // Closing QueueSesssion. System.out.println("Closing Session"); session.close(); session = null; // Closing QueueConnection. System.out.println("Closing Connection"); connection.close(); connection = null; } }