Putting simple text message on a jms queue
try {
String jndi_pref = "java:comp/env/";
String qConnectionFactoryJndi = "qConnectionFactoryJndi";
String qJndi = "qJndi" ;
InitialContext context = new InitialContext();
QueueConnectionFactory qConnectionFactory = (QueueConnectionFactory) context.lookup(qConnectionFactoryJndi);
Queue queue = (Queue) context.lookup(qJndi);
logger.debug("Resource " + queue.getQueueName() + " obtained");
QueueConnection qConnection = qConnectionFactory.createQueueConnection();
logger.debug("connection to queue connection factory " + qConnectionFactoryJndi + " created.");
QueueSession qSession = qConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
logger.debug("session created");
QueueBrowser qBrowser = null;
Enumeration enum = null;
QueueSender sender = qSession.createSender(queue);
logger.debug("queue sender created");
TextMessage message = qSession.createTextMessage();
message.setText("txtMessage ...");
sender.send(message);
logger.info("Message was sent to queue " + queue.getQueueName());
sender.close();
logger.debug("sender closed");
qSession.close();
logger.debug("session closed");
qConnection.close();
logger.info("Connection closed");
} catch (NamingException ne) {
// log & throw
} catch (JMSException e) {
// log & throw
}
String jndi_pref = "java:comp/env/";
String qConnectionFactoryJndi = "qConnectionFactoryJndi";
String qJndi = "qJndi" ;
InitialContext context = new InitialContext();
QueueConnectionFactory qConnectionFactory = (QueueConnectionFactory) context.lookup(qConnectionFactoryJndi);
Queue queue = (Queue) context.lookup(qJndi);
logger.debug("Resource " + queue.getQueueName() + " obtained");
QueueConnection qConnection = qConnectionFactory.createQueueConnection();
logger.debug("connection to queue connection factory " + qConnectionFactoryJndi + " created.");
QueueSession qSession = qConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
logger.debug("session created");
QueueBrowser qBrowser = null;
Enumeration enum = null;
QueueSender sender = qSession.createSender(queue);
logger.debug("queue sender created");
TextMessage message = qSession.createTextMessage();
message.setText("txtMessage ...");
sender.send(message);
logger.info("Message was sent to queue " + queue.getQueueName());
sender.close();
logger.debug("sender closed");
qSession.close();
logger.debug("session closed");
qConnection.close();
logger.info("Connection closed");
} catch (NamingException ne) {
// log & throw
} catch (JMSException e) {
// log & throw
}