Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

The Application Client

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

connectionFactory = 
    (ConnectionFactory) jndiContext.lookup
    ("java:comp/env/jms/MyConnectionFactory");
destination = 
    (Queue) jndiContext.lookup("java:comp/env/jms/QueueName"); 

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

connection = connectionFactory.createConnection();
session = connection.createSession(false,
    Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(destination); 

Finally, the client sends several messages to the queue:

message = session.createTextMessage();

for (int i = 0; i < NUM_MSGS; i++) {
     message.setText("This is message " + (i + 1));
     System.out.println("Sending message: " +
         message.getText());
     messageProducer.send(message);
} 
Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.