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