Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett
Created May 20, 2014 05:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save edwardbeckett/af9bfeaddb87a17d786d to your computer and use it in GitHub Desktop.
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