Skip to content

Instantly share code, notes, and snippets.

@rzymek
Created November 15, 2013 10:29
Show Gist options
  • Save rzymek/7482288 to your computer and use it in GitHub Desktop.
Save rzymek/7482288 to your computer and use it in GitHub Desktop.
package com.centurion.mq;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@SuppressWarnings("unused")
public final class JMSUtils {
private static final Log log = LogFactory.getLog(JMSUtils.class);
private static final boolean NON_TRANSACTIONAL = false;
private static final boolean TRANSACTIONAL = true;
private JMSUtils() {
}
public static void send(String text, Queue dest, ConnectionFactory factory) throws JMSException {
Connection conn = factory.createConnection();
try {
Session s = conn.createSession(TRANSACTIONAL, Session.AUTO_ACKNOWLEDGE);
try {
MessageProducer producer = s.createProducer(dest);
try {
Message msg = s.createTextMessage(text);
producer.send(msg);
log.debug("Sent " + msg.getJMSMessageID());
} finally {
producer.close();
}
} finally {
s.close();
}
} finally {
conn.close();
}
log.debug("Sending ok.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment