O'Reilly logo

J2EE™ Tutorial, The by Beth Stearns, Monica Pawlan, Eric Jendrock, Kim Haase, Dale Green, Stephanie Bodoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The J2EE Application Client

The SimpleMessageClient sends messages to the queue that the SimpleMessageBean listens to. The client starts out by locating the connection factory and queue:

queueConnectionFactory = (QueueConnectionFactory) 
    jndiContext.lookup 
    ("java:comp/env/jms/MyQueueConnectionFactory"); 
queue = (Queue) 
     jndiContext.lookup("java:comp/env/jms/QueueName"); 

Next, the client creates the queue connection, session, and sender:

queueConnection = 
    queueConnectionFactory.createQueueConnection(); 
queueSession = 
    queueConnection.createQueueSession(false, 
    Session.AUTO_ACKNOWLEDGE); 
queueSender = queueSession.createSender(queue); 

Finally, the client sends several messages to the queue:

 message = queueSession.createTextMessage(); for (int ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required