Search in sources :

Example 86 with TemporaryQueue

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

the class TemporaryQueueTest method testClosingSessionDoesNotDeleteQueue.

@Test
public void testClosingSessionDoesNotDeleteQueue() throws Exception {
    final Connection connection = getConnection();
    try {
        final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryQueue queue = session1.createTemporaryQueue();
        assertNotNull("Temporary queue cannot be null", queue);
        MessageProducer producer = session1.createProducer(queue);
        String messageText = "Hello World!";
        producer.send(session1.createTextMessage(messageText));
        session1.close();
        connection.start();
        MessageConsumer consumer = session2.createConsumer(queue);
        Message message = consumer.receive(getReceiveTimeout());
        assertTrue("Received message not a text message", message instanceof TextMessage);
        assertEquals("Incorrect message text", messageText, ((TextMessage) message).getText());
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 87 with TemporaryQueue

use of javax.jms.TemporaryQueue in project wildfly by wildfly.

the class MDBWithVaultedPropertiesTestCase method sendAndReceiveMessage.

@Test
public void sendAndReceiveMessage() {
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        String text = UUID.randomUUID().toString();
        context.createProducer().setJMSReplyTo(replyTo).send(queue, text);
        JMSConsumer consumer = context.createConsumer(replyTo);
        String reply = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
        assertEquals(text, reply);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 88 with TemporaryQueue

use of javax.jms.TemporaryQueue in project eap-additional-testsuite by jboss-set.

the class VaultedInjectedJMSContextTestCase method sendMessage.

@Test
public void sendMessage() throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text);
        JMSConsumer consumer = context.createConsumer(tempQueue);
        String reply = consumer.receiveBody(String.class, adjust(2000));
        assertEquals(text, reply);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 89 with TemporaryQueue

use of javax.jms.TemporaryQueue in project eap-additional-testsuite by jboss-set.

the class InjectedJMSContextTestCase method sendWith_REQUIRED_transaction.

private void sendWith_REQUIRED_transaction(boolean rollback) throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text, rollback);
        assertMessageIsReceived(tempQueue, context, text, rollback);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext)

Example 90 with TemporaryQueue

use of javax.jms.TemporaryQueue in project javaee7-samples by javaee-samples.

the class JmsClient method process.

// <1> we need to send message in the middle of the method, therefore we cannot be transactional
@TransactionAttribute(NOT_SUPPORTED)
public String process(String request) {
    TextMessage requestMessage = jms.createTextMessage(request);
    TemporaryQueue responseQueue = jms.createTemporaryQueue();
    jms.createProducer().setJMSReplyTo(// <2> set the temporary queue as replyToDestination
    responseQueue).send(requestQueue, // <3> immediately send the request message
    requestMessage);
    try (JMSConsumer consumer = jms.createConsumer(responseQueue)) {
        // <4> listen on the temporary queue
        // <5> wait for a +TextMessage+ to arrive
        String response = consumer.receiveBody(String.class, 20000);
        if (response == null) {
            // <6> +receiveBody+ returns +null+ in case of timeout
            throw new IllegalStateException("Message processing timed out");
        }
        return response;
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) TransactionAttribute(javax.ejb.TransactionAttribute)

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