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 ...

Get J2EE™ Tutorial, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.