public class Sender {
public static void main() {
...
try {
InitialContext initialContext = new InitialContext(); /* 1 */
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
initialContext.lookup("java:comp/env/jms/QueueConnectionFactory"); /* 2 */
Queue queue = (Queue)initialContext.lookup("java:comp/env/jms/Queue"); /* 3 */
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(); /* 4 */
QueueSession queueSession = queueConnection.createQueueSession(true, 0); /* 5 */
QueueSender queueSender = queueSession.createSender(queue); /* 6 */
queueSender.send(Message); /* 7 */
queueSession.commit(); /* 8 */
queueConnection.close(); /* 9 */
} catch( Exception e ) {
...
}
...
}
} |