The J2EETM Tutorial
Home
TOC
Index
PREV TOP NEXT Search
Feedback

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 i = 0; i < NUM_MSGS; i++) {	
     message.setText("This is message " + (i + 1));	
     System.out.println("Sending message: " +	
         message.getText());	
     queueSender.send(message);	
}
 
Home
TOC
Index
PREV TOP NEXT Search
Feedback