Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett edwardbeckett/JMS
Created May 20, 2014

Embed
What would you like to do?
public void send(Object obj, Queue queue, String CorrelationId) throws JMSException {
Connection connection = null;
Session session = null;
Message message = null;
MessageProducer producer = null;
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
message = session.createObjectMessage((Serializable) obj);
message.setStringProperty("DestinationQueue", queue.getQueueName());
message.setJMSCorrelationID(CorrelationId);
producer = session.createProducer(queue);
producer.setTimeToLive(timelife);
producer.send(message);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (producer != null) {
try {
producer.close();
} catch (Exception ignore) {
}
}
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.