Search in sources :

Example 6 with QueueReceiver

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

the class MessageConsumerTest method testGetQueueOnClosedConsumer.

@Test
public void testGetQueueOnClosedConsumer() throws Exception {
    Connection consumerConnection = null;
    try {
        consumerConnection = createConnection();
        Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
        queueConsumer.close();
        try {
            ((QueueReceiver) queueConsumer).getQueue();
            Assert.fail("must throw a JMS IllegalStateException");
        } catch (javax.jms.IllegalStateException e) {
        // OK
        }
    } finally {
        if (consumerConnection != null) {
            consumerConnection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) QueueReceiver(javax.jms.QueueReceiver) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 7 with QueueReceiver

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

the class MessageConsumerTest method testGetQueue.

@Test
public void testGetQueue() throws Exception {
    Connection consumerConnection = null;
    try {
        consumerConnection = createConnection();
        Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
        Queue q = ((QueueReceiver) queueConsumer).getQueue();
        ProxyAssertSupport.assertEquals(queue1, q);
    } finally {
        if (consumerConnection != null) {
            consumerConnection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) QueueReceiver(javax.jms.QueueReceiver) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 8 with QueueReceiver

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

the class MessageDrivenTimeoutTestCase method receiveMessage.

static String receiveMessage(Queue replyQueue, InitialContext initCtx, boolean isCommitExpected) throws Exception {
    QueueConnection connection = getConnection(initCtx);
    connection.start();
    try {
        final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        final QueueReceiver receiver = session.createReceiver(replyQueue);
        // when expecting commit (message should be in queue): wait a bit longer before failing
        // when expecting rollback (message should not be in queue): fail faster only till timeout elapses
        final Message reply = receiver.receive(TimeoutUtil.adjust(isCommitExpected ? 5000 : TxTestUtil.timeoutWaitTime_ms));
        // waiting for synchro could be finished before checking
        Thread.sleep(TimeoutUtil.adjust(500));
        if (reply == null)
            return null;
        return ((TextMessage) reply).getText();
    } finally {
        connection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueReceiver(javax.jms.QueueReceiver) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 9 with QueueReceiver

use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.

the class MixedConsumerCheckIT method testAsyncThenSyncReceive.

/**
 * Listener with a Consumer. Uses message listener (asynchronous receive).
 * Try to receive() from different queue on same session.
 * @throws javax.jms.IllegalStateException if test succeeds.
 */
@Test
public void testAsyncThenSyncReceive() throws Exception {
    assertThrows(javax.jms.IllegalStateException.class, () -> {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        Queue queueTwo = queueSession.createQueue(QUEUE_NAME_TWO);
        QueueReceiver queueReceiver = queueSession.createReceiver(queue);
        QueueReceiver queueReceiverTwo = queueSession.createReceiver(queueTwo);
        TestMessageListener listener = new TestMessageListener();
        queueReceiver.setMessageListener(listener);
        // should throw an exception
        queueReceiverTwo.receiveNoWait();
    });
}
Also used : QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) Test(org.junit.jupiter.api.Test)

Example 10 with QueueReceiver

use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.

the class SSLSimpleQueueMessageIT method messageTestBase.

private void messageTestBase(MessageTestType mtt) throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        drainQueue(queueSession, queue);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queueSender.send(mtt.gen(queueSession, (Serializable) queue));
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Also used : Serializable(java.io.Serializable) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Aggregations

QueueReceiver (javax.jms.QueueReceiver)56 QueueSession (javax.jms.QueueSession)47 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)28 Message (javax.jms.Message)25 QueueSender (javax.jms.QueueSender)25 Test (org.junit.jupiter.api.Test)17 QueueConnection (javax.jms.QueueConnection)13 Serializable (java.io.Serializable)11 JMSException (javax.jms.JMSException)10 Test (org.junit.Test)10 QueueConnectionFactory (javax.jms.QueueConnectionFactory)6 BytesMessage (javax.jms.BytesMessage)5 InitialContext (javax.naming.InitialContext)5 Destination (javax.jms.Destination)4 MessageProducer (javax.jms.MessageProducer)4 NamingException (javax.naming.NamingException)4 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3