Created
November 15, 2013 10:29
-
-
Save rzymek/7482288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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