Search in sources :

Example 86 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpPresettledReceiverTest method testPresettledReceiverWithinBoundsOfActiveTXWithSendAndRollback.

@Test(timeout = 60000)
public void testPresettledReceiverWithinBoundsOfActiveTXWithSendAndRollback() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    final Queue queue = getProxyToQueue(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    sender.send(message);
    Wait.assertEquals(1, queue::getMessageCount);
    AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
    session.begin();
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    assertTrue(received.getWrappedDelivery().remotelySettled());
    message = new AmqpMessage();
    message.setText("Test-Message - Rolled Back");
    sender.send(message);
    session.rollback();
    assertEquals(0, queue.getMessageCount());
    sender.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 87 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpPresettledReceiverTest method doTestPresettledReceiverWithinBoundsOfActiveTX.

private void doTestPresettledReceiverWithinBoundsOfActiveTX(boolean commit) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    final Queue queue = getProxyToQueue(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    sender.send(message);
    Wait.assertEquals(1, queue::getMessageCount);
    AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
    session.begin();
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    assertTrue(received.getWrappedDelivery().remotelySettled());
    if (commit) {
        session.commit();
    } else {
        session.rollback();
    }
    assertEquals(0, queue.getMessageCount());
    sender.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Example 88 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpReceiverDispositionTest method doModifiedDispositionTestImpl.

private void doModifiedDispositionTestImpl(Boolean deliveryFailed, Boolean undeliverableHere) throws Exception {
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    receiver1.flow(1);
    AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
    assertNotNull("did not receive message first time", message);
    Message protonMessage = message.getWrappedMessage();
    assertNotNull(protonMessage);
    assertEquals("Unexpected initial value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
    message.modified(deliveryFailed, undeliverableHere);
    // Remote must not redispatch to the client if undeliverable here is true
    if (Boolean.TRUE.equals(undeliverableHere)) {
        receiver1.flow(1);
        message = receiver1.receive(1, TimeUnit.SECONDS);
        assertNull("Should not receive message again", message);
    }
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    receiver2.flow(1);
    message = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull("did not receive message again", message);
    int expectedDeliveryCount = 0;
    if (Boolean.TRUE.equals(deliveryFailed)) {
        expectedDeliveryCount = 1;
    }
    message.accept();
    Message protonMessage2 = message.getWrappedMessage();
    assertNotNull(protonMessage2);
    assertEquals("Unexpected updated value for AMQP delivery-count", expectedDeliveryCount, protonMessage2.getDeliveryCount());
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(org.apache.qpid.proton.message.Message) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Example 89 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpReceiverDispositionTest method testReleasedDisposition.

@Test(timeout = 30000)
public void testReleasedDisposition() throws Exception {
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    receiver1.flow(1);
    AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    assertNotNull("did not receive message first time", message);
    assertEquals("MessageID:0", message.getMessageId());
    Message protonMessage = message.getWrappedMessage();
    assertNotNull(protonMessage);
    assertEquals("Unexpected initial value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
    receiver2.flow(1);
    message.release();
    // Read the message again and validate its state
    message = receiver2.receive(10, TimeUnit.SECONDS);
    assertNotNull("did not receive message again", message);
    assertEquals("MessageID:0", message.getMessageId());
    message.accept();
    protonMessage = message.getWrappedMessage();
    assertNotNull(protonMessage);
    assertEquals("Unexpected updated value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(org.apache.qpid.proton.message.Message) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 90 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpReceiverDrainTest method doTestReceiverCanDrainMessages.

private void doTestReceiverCanDrainMessages(boolean topic) throws Exception {
    final String destinationName;
    if (topic) {
        destinationName = getTopicName();
    } else {
        destinationName = getQueueName();
    }
    int MSG_COUNT = 20;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(destinationName);
    sendMessages(destinationName, MSG_COUNT);
    Queue queueView = getProxyToQueue(destinationName);
    Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);
    Wait.assertEquals(0, queueView::getDeliveringCount);
    receiver.drain(MSG_COUNT);
    for (int i = 0; i < MSG_COUNT; ++i) {
        AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
        assertNotNull("Failed to read message: " + (i + 1), message);
        IntegrationTestLogger.LOGGER.info("Read message: " + message.getMessageId());
        message.accept();
    }
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Aggregations

AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)115 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)114 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)114 Test (org.junit.Test)100 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)82 Queue (org.apache.activemq.artemis.core.server.Queue)56 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)16 Source (org.apache.qpid.proton.amqp.messaging.Source)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)4 Delivery (org.apache.qpid.proton.engine.Delivery)4