Search in sources :

Example 51 with QueueSender

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

the class SimpleSendReceiveTransactionIT method testSendAndCommitAndReceiveMessage.

@Test
public void testSendAndCommitAndReceiveMessage() throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(true, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage message = queueSession.createTextMessage(MESSAGE);
        queueSender.send(message);
        queueSession.commit();
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    TextMessage message = (TextMessage) queueReceiver.receive();
    assertEquals(MESSAGE, message.getText());
}
Also used : QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 52 with QueueSender

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

the class MetricsCollectionIT method sendAndConsumeMessage.

protected void sendAndConsumeMessage() throws Exception {
    MessageTestType mtt = MessageTestType.TEXT;
    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)

Example 53 with QueueSender

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

the class MultipleBrowseQueueMessageIT method messageTestBase.

private void messageTestBase(MessageTestType mtt, String selector, int numExpected) 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);
    {
        // Browse queue before receiving message
        QueueBrowser queueBrowser = queueSession.createBrowser(queue, selector);
        for (int repeat = 0; repeat < REPEATS; ++repeat) {
            Enumeration<?> e = queueBrowser.getEnumeration();
            int numE = 0;
            Message msg = null;
            while (e.hasMoreElements()) {
                ++numE;
                msg = (Message) e.nextElement();
                mtt.check(msg, (Serializable) queue);
            }
            assertEquals(numExpected, numE, "Wrong number of messages on browse queue");
        }
    }
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Also used : Serializable(java.io.Serializable) Enumeration(java.util.Enumeration) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) QueueBrowser(javax.jms.QueueBrowser)

Example 54 with QueueSender

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

the class ObjectMessageSerializationIT method testReceiveObjectMessageWithPayload.

protected void testReceiveObjectMessageWithPayload(Object payload) 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.send(MessageTestType.OBJECT.gen(queueSession, (Serializable) payload));
    } finally {
        reconnect(Arrays.asList("java.lang", "com.rabbitmq.jms"));
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    RMQObjectMessage m = (RMQObjectMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
    assertEquals(m.getObject(), payload);
    assertEquals(m.getObject(TRUSTED_PACKAGES), payload);
}
Also used : RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) Serializable(java.io.Serializable) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Example 55 with QueueSender

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

the class AsyncConsumerOnMessageHangIT method testSendAndAsyncReceiveTextMessageWithHang.

/**
 * Basic send and receive with a Consumer. Uses serial send followed by async receive.
 * @throws Exception if test error.
 */
@Test
public void testSendAndAsyncReceiveTextMessageWithHang() throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage message = queueSession.createTextMessage(MESSAGE);
        queueSender.send(message);
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    MessageListener listener = new MessageListener();
    queueReceiver.setMessageListener(listener);
    Thread.sleep(4000);
    TextMessage message = (TextMessage) listener.getLastMessage();
    assertEquals(MESSAGE, message.getText());
    assertEquals(1, listener.getMessageCount());
    assertTrue(listener.isSuccess());
    assertTrue(listener.isInterrupted());
}
Also used : QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

QueueSender (javax.jms.QueueSender)59 QueueSession (javax.jms.QueueSession)54 Queue (javax.jms.Queue)36 TextMessage (javax.jms.TextMessage)28 QueueReceiver (javax.jms.QueueReceiver)25 JMSException (javax.jms.JMSException)14 Message (javax.jms.Message)14 QueueConnection (javax.jms.QueueConnection)14 Test (org.junit.jupiter.api.Test)14 Serializable (java.io.Serializable)11 ObjectMessage (javax.jms.ObjectMessage)10 Test (org.junit.Test)8 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)5 InitialContext (javax.naming.InitialContext)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MapMessage (javax.jms.MapMessage)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 IFSAQueue (com.ing.ifsa.IFSAQueue)3 GetResponse (com.rabbitmq.client.GetResponse)3