use of javax.jms.TemporaryQueue in project karaf by apache.
the class PooledConnection method cleanupConnectionTemporaryDestinations.
/**
* Remove all of the temporary destinations created for this connection.
* This is important since the underlying connection may be reused over a
* long period of time, accumulating all of the temporary destinations from
* each use. However, from the perspective of the lifecycle from the
* client's view, close() closes the connection and, therefore, deletes all
* of the temporary destinations created.
*/
protected void cleanupConnectionTemporaryDestinations() {
for (TemporaryQueue tempQueue : connTempQueues) {
try {
tempQueue.delete();
} catch (JMSException ex) {
LOG.info("failed to delete Temporary Queue \"" + tempQueue.toString() + "\" on closing pooled connection: " + ex.getMessage());
}
}
connTempQueues.clear();
for (TemporaryTopic tempTopic : connTempTopics) {
try {
tempTopic.delete();
} catch (JMSException ex) {
LOG.info("failed to delete Temporary Topic \"" + tempTopic.toString() + "\" on closing pooled connection: " + ex.getMessage());
}
}
connTempTopics.clear();
}
use of javax.jms.TemporaryQueue in project karaf by apache.
the class PooledSession method createTemporaryQueue.
@Override
public TemporaryQueue createTemporaryQueue() throws JMSException {
TemporaryQueue result;
result = getInternalSession().createTemporaryQueue();
// Notify all of the listeners of the created temporary Queue.
for (PooledSessionEventListener listener : this.sessionEventListeners) {
listener.onTemporaryQueueCreate(result);
}
return result;
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class HelloBean method sendMessage.
public String sendMessage() throws Exception {
String destinationName = "java:jboss/exported/queue/TestQueue";
Context ic = null;
ConnectionFactory cf = null;
Connection connection = null;
try {
ic = getInitialContext();
cf = (ConnectionFactory) ic.lookup("java:/ConnectionFactory");
Queue queue = (Queue) ic.lookup(destinationName);
connection = cf.createConnection("guest", "guest");
// we need to start connection for consumer
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TextMessage message = session.createTextMessage("hello goodbye");
TemporaryQueue replyQueue = session.createTemporaryQueue();
message.setJMSReplyTo(replyQueue);
sender.send(message);
MessageConsumer consumer = session.createConsumer(replyQueue);
TextMessage replyMsg = (TextMessage) consumer.receive(5000);
log.trace("Message received:" + replyMsg);
return replyMsg.getText();
} finally {
if (ic != null) {
try {
ic.close();
} catch (Exception ignore) {
}
}
closeConnection(connection);
}
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class RunAsTestCaseEJBMDB method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory cf = null;
Connection connection = null;
Session session = null;
try {
cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
connection = cf.createConnection("guest", "guest");
//for consumer we need to start connection
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage message = session.createTextMessage("hello goodbye");
message.setJMSReplyTo(replyQueue);
sender.send(message);
log.trace("testSendMessage(): Message sent!");
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
} finally {
if (session != null) {
session.close();
}
closeConnection(connection);
}
}
use of javax.jms.TemporaryQueue in project spring-framework by spring-projects.
the class JmsInvokerClientInterceptor method doExecuteRequest.
/**
* Actually execute the given request, sending the invoker request message
* to the specified target queue and waiting for a corresponding response.
* <p>The default implementation is based on standard JMS send/receive,
* using a {@link javax.jms.TemporaryQueue} for receiving the response.
* @param session the JMS Session to use
* @param queue the resolved target Queue to send to
* @param requestMessage the JMS Message to send
* @return the RemoteInvocationResult object
* @throws JMSException in case of JMS failure
*/
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
TemporaryQueue responseQueue = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
try {
responseQueue = session.createTemporaryQueue();
producer = session.createProducer(queue);
consumer = session.createConsumer(responseQueue);
requestMessage.setJMSReplyTo(responseQueue);
producer.send(requestMessage);
long timeout = getReceiveTimeout();
return (timeout > 0 ? consumer.receive(timeout) : consumer.receive());
} finally {
JmsUtils.closeMessageConsumer(consumer);
JmsUtils.closeMessageProducer(producer);
if (responseQueue != null) {
responseQueue.delete();
}
}
}
Aggregations