Search in sources :

Example 81 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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 82 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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 83 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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 84 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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)

Example 85 with AmqpReceiver

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

the class AmqpReceiverDrainTest method doTestMultipleZeroResultPulls.

private void doTestMultipleZeroResultPulls(boolean topic) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final String destinationName;
    if (topic) {
        destinationName = getTopicName();
    } else {
        destinationName = getQueueName();
    }
    AmqpReceiver receiver = session.createReceiver(destinationName);
    receiver.flow(10);
    Queue queueView = getProxyToQueue(destinationName);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0, queueView.getDeliveringCount());
    assertEquals(10, receiver.getReceiver().getRemoteCredit());
    assertNull(receiver.pull(1, TimeUnit.SECONDS));
    assertEquals(0, receiver.getReceiver().getRemoteCredit());
    assertNull(receiver.pull(1, TimeUnit.SECONDS));
    assertNull(receiver.pull(1, TimeUnit.SECONDS));
    assertEquals(0, receiver.getReceiver().getRemoteCredit());
    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)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)118 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)118 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)118 Test (org.junit.Test)101 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)61 Queue (org.apache.activemq.artemis.core.server.Queue)59 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)17 Source (org.apache.qpid.proton.amqp.messaging.Source)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 Receiver (org.apache.qpid.proton.engine.Receiver)6 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 Wait (org.apache.activemq.artemis.tests.util.Wait)3 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)3 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2