Search in sources :

Example 1 with TemporaryQueue

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();
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) TemporaryTopic(javax.jms.TemporaryTopic)

Example 2 with TemporaryQueue

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;
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue)

Example 3 with TemporaryQueue

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);
    }
}
Also used : InitialContext(javax.naming.InitialContext) SessionContext(javax.ejb.SessionContext) Context(javax.naming.Context) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 4 with TemporaryQueue

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);
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with TemporaryQueue

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();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5