Steps to post a message to JMS Queue:-
1. Create JNDI context
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context jndiContext = new InitialContext(ht);
2. Create the QueueConnectionFactory
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup(connFactoryJNDIName);
3. Create the Queue
Queue queue = (Queue) jndiContext.lookup(queueName);
4. Create the QueueConnection
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
5. Create the QueueSession
QueueSession .queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
6. Create the QueueSender
QueueSender queueSender = queueSession.createSender(queue);
7. Create the Message(Text,Byte,Object,Stream)
TextMessage message = queueSession.createTextMessage();
8. Set Message
message.setText("str_message");
9. Send Message
queueSender.send(message);
No comments:
Post a Comment