Search in sources :

Example 6 with TemporaryQueue

use of javax.jms.TemporaryQueue in project camel by apache.

the class DefaultDestinationCreationStrategyTest method testTemporaryQueueCreation.

@Test
public void testTemporaryQueueCreation() throws Exception {
    TemporaryQueue destination = (TemporaryQueue) strategy.createTemporaryDestination(getSession(), false);
    assertNotNull(destination);
    assertNotNull(destination.getQueueName());
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) Test(org.junit.Test)

Example 7 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class AuthenticationTest method assertConnectivity.

private void assertConnectivity(final int port, final String userName, final String userPassword, final String mechanism) throws Exception {
    Connection connection = getConnectionBuilder().setPort(port).setUsername(userName).setPassword(userPassword).setSaslMechanisms(mechanism).build();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        assertNotNull("Temporary queue was not created", queue);
    } finally {
        connection.close();
    }
    try {
        getConnectionBuilder().setPort(port).setUsername(userName).setPassword("invalid" + userPassword).setSaslMechanisms(mechanism).build();
        fail("Connection is established for invalid password");
    } catch (JMSException e) {
    // pass
    }
    try {
        getConnectionBuilder().setPort(port).setUsername("invalid" + userName).setPassword(userPassword).setSaslMechanisms(mechanism).build();
        fail("Connection is established for invalid user name");
    } catch (JMSException e) {
    // pass
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 8 with TemporaryQueue

use of javax.jms.TemporaryQueue in project spring-integration by spring-projects.

the class JmsOutboundGateway method retryableReceiveReply.

/*
	 * If the replyTo is not temporary, and the connection is lost while waiting for a reply, reconnect for
	 * up to receiveTimeout.
	 */
private javax.jms.Message retryableReceiveReply(Session session, Destination replyTo, String messageSelector) throws JMSException {
    // NOSONAR
    Connection consumerConnection = null;
    Session consumerSession = session;
    MessageConsumer messageConsumer = null;
    JMSException exception = null;
    boolean isTemporaryReplyTo = replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic;
    long replyTimeout = isTemporaryReplyTo ? Long.MIN_VALUE : this.receiveTimeout < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + this.receiveTimeout;
    try {
        do {
            try {
                messageConsumer = consumerSession.createConsumer(replyTo, messageSelector);
                javax.jms.Message reply = receiveReplyMessage(messageConsumer);
                if (reply == null) {
                    if (replyTimeout > System.currentTimeMillis()) {
                        throw new JMSException("Consumer closed before timeout");
                    }
                }
                return reply;
            } catch (JMSException e) {
                exception = e;
                if (logger.isDebugEnabled()) {
                    logger.debug("Connection lost waiting for reply, retrying: " + e.getMessage());
                }
                do {
                    try {
                        consumerConnection = createConnection();
                        consumerSession = createSession(consumerConnection);
                        break;
                    } catch (JMSException ee) {
                        exception = ee;
                        if (logger.isDebugEnabled()) {
                            logger.debug("Could not reconnect, retrying: " + ee.getMessage());
                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e1) {
                            Thread.currentThread().interrupt();
                            return null;
                        }
                    }
                } while (replyTimeout > System.currentTimeMillis());
            }
        } while (replyTimeout > System.currentTimeMillis());
        if (isTemporaryReplyTo) {
            return null;
        } else {
            throw exception;
        }
    } finally {
        if (consumerSession != session) {
            JmsUtils.closeSession(consumerSession);
            JmsUtils.closeConnection(consumerConnection);
        }
        JmsUtils.closeMessageConsumer(messageConsumer);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) TemporaryTopic(javax.jms.TemporaryTopic)

Example 9 with TemporaryQueue

use of javax.jms.TemporaryQueue in project scout.rt by eclipse.

the class JmsMomImplementor method requestImpl.

protected <REQUEST, REPLY> Message requestImpl(final IBiDestination<REQUEST, REPLY> destination, final REQUEST requestObject, final PublishInput input, String replyId) throws JMSException {
    Message responseMessage;
    IJmsSessionProvider sessionProvider = createSessionProvider(destination, false);
    try {
        TemporaryQueue temporaryQueue = sessionProvider.getTemporaryQueue();
        MessageConsumer responseQueueConsumer = sessionProvider.getSession().createConsumer(temporaryQueue);
        // send request message
        JmsMessageWriter messageWriter = JmsMessageWriter.newInstance(sessionProvider.getSession(), resolveMarshaller(destination)).writeReplyTo(temporaryQueue).writeReplyId(replyId).writeProperties(input.getProperties()).writeTransferObject(requestObject);
        send(sessionProvider, destination, messageWriter, input);
        // receive response message
        responseMessage = responseQueueConsumer.receive();
    } catch (JMSException e) {
        if (IFuture.CURRENT.get().isCancelled()) {
            // if job was canceled, we ignore JMSException as these are exceptions because of interruption
            LOG.info("Request job canceled; {}", e.getMessage());
            return null;
        } else {
            throw e;
        }
    } finally {
        sessionProvider.close();
    }
    // After closing session, delete not required temporary queue. The queue is associated with the connection and exists as long as the connection is alive.
    sessionProvider.deleteTemporaryQueue();
    return responseMessage;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException)

Example 10 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class ActiveMQRASession method createTemporaryQueue.

/**
 * Create a temporary queue
 *
 * @return The temporary queue
 * @throws JMSException Thrown if an error occurs
 */
@Override
public TemporaryQueue createTemporaryQueue() throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
        throw new IllegalStateException("Cannot create temporary queue for javax.jms.TopicSession");
    }
    lock();
    try {
        Session session = getSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createTemporaryQueue " + session);
        }
        TemporaryQueue temp = session.createTemporaryQueue();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createdTemporaryQueue " + session + " temp=" + temp);
        }
        sf.addTemporaryQueue(temp);
        return temp;
    } finally {
        unlock();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) TemporaryQueue(javax.jms.TemporaryQueue) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

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