/** * @param queueName * @param message * @throws Exception */ public static void sendMessage(String queueName, Message message) throws Exception { MessageProducer producer = (MessageProducer) producerPool.borrowObject(queueName); try { producer.send(message); } finally { producerPool.returnObject(queueName, producer); } }
/** * Create a TextMessage destined for the specified queue. * * @param queueName the name of the destination queue * @param message the message text * @return a TextMessage object * @throws Exception thrown if an exception occurs */ public static TextMessage createTextMessage(String queueName, String message) throws Exception { Session jmsSession = (Session) sessionPool.borrowObject(queueName); try { return jmsSession.createTextMessage(message); } finally { sessionPool.returnObject(queueName, jmsSession); } }
/** {@inheritDoc} */ @Override public Object makeObject(Object key) throws Exception { Session jmsSession = (Session) sessionPool.borrowObject(key.toString()); try { // Create the destination (Topic or Queue) Destination destination = jmsSession.createTopic(key.toString()); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = jmsSession.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); return producer; } finally { sessionPool.returnObject(key.toString(), jmsSession); } }