Search in sources :

Example 51 with AmqpMessage

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

the class AmqpPresettledReceiverTest method testPresettledReceiverReadsAllMessagesInWhenReadInBatches.

@Test(timeout = 60000)
public void testPresettledReceiverReadsAllMessagesInWhenReadInBatches() throws Exception {
    final int MSG_COUNT = 100;
    sendMessages(getQueueName(), MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
    final Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(MSG_COUNT, queueView.getMessageCount());
    // Consume all 100 but do so in batches by flowing only limited credit.
    receiver.flow(20);
    // consume less that flow
    for (int j = 0; j < 10; j++) {
        assertNotNull(receiver.receive(5, TimeUnit.SECONDS));
    }
    // flow more and consume all
    receiver.flow(10);
    for (int j = 0; j < 20; j++) {
        assertNotNull(receiver.receive(5, TimeUnit.SECONDS));
    }
    // remainder
    receiver.flow(70);
    for (int j = 0; j < 70; j++) {
        assertNotNull(receiver.receive(5, TimeUnit.SECONDS));
    }
    receiver.close();
    System.out.println("Message Count after all consumed: " + queueView.getMessageCount());
    // Open a new receiver and see if any message are left on the Queue
    receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    if (received != null) {
        System.out.println("Message read: " + received.getMessageId());
    }
    assertNull(received);
    assertEquals(0, queueView.getMessageCount());
    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) Test(org.junit.Test)

Example 52 with AmqpMessage

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

the class AmqpPresettledReceiverTest method testPresettledReceiverReadsAllMessages.

@Test(timeout = 60000)
public void testPresettledReceiverReadsAllMessages() throws Exception {
    final int MSG_COUNT = 100;
    sendMessages(getQueueName(), MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
    final Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(MSG_COUNT, queueView.getMessageCount());
    receiver.flow(MSG_COUNT);
    for (int i = 0; i < MSG_COUNT; ++i) {
        assertNotNull(receiver.receive(5, TimeUnit.SECONDS));
    }
    receiver.close();
    System.out.println("Message Count after all consumed: " + queueView.getMessageCount());
    // Open a new receiver and see if any message are left on the Queue
    receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    if (received != null) {
        System.out.println("Message read: " + received.getMessageId());
    }
    assertNull(received);
    assertEquals(0, queueView.getMessageCount());
    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) Test(org.junit.Test)

Example 53 with AmqpMessage

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

the class AmqpPresettledReceiverTest method testPresettledReceiverAndNonPresettledReceiverOnSameQueue.

@Test(timeout = 60000)
public void testPresettledReceiverAndNonPresettledReceiverOnSameQueue() throws Exception {
    final int MSG_COUNT = 2;
    sendMessages(getQueueName(), MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName(), null, false, true);
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    final Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(MSG_COUNT, queueView.getMessageCount());
    receiver1.flow(1);
    receiver2.flow(1);
    AmqpMessage message1 = receiver1.receive(5, TimeUnit.SECONDS);
    AmqpMessage message2 = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(message1);
    assertNotNull(message2);
    // Receiver 1 is presettled so messages are not accepted.
    assertTrue(message1.getWrappedDelivery().remotelySettled());
    // Receiver 2 is not presettled so it needs to accept.
    message2.accept();
    receiver1.close();
    receiver2.close();
    System.out.println("Message Count after all consumed: " + queueView.getMessageCount());
    // Should be nothing left on the Queue
    AmqpReceiver receiver3 = session.createReceiver(getQueueName());
    receiver3.flow(1);
    AmqpMessage received = receiver3.receive(5, TimeUnit.SECONDS);
    if (received != null) {
        System.out.println("Message read: " + received.getMessageId());
    }
    assertNull(received);
    assertEquals(0, queueView.getMessageCount());
    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) Test(org.junit.Test)

Example 54 with AmqpMessage

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

the class AmqpPurgeOnNoConsumersTest method testQueueReceiverReadMessage.

@Test(timeout = 60000)
public void testQueueReceiverReadMessage() throws Exception {
    AmqpConnection connection = null;
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    AmqpClient client = createAmqpClient();
    connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final AmqpReceiver receiver = session.createReceiver(queue);
    QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    assertEquals(0, queueView.getMessageCount());
    sendMessages(queue, 5, null, true);
    Wait.assertEquals(5, queueView::getMessageCount);
    receiver.flow(5);
    for (int i = 0; i < 4; i++) {
        try {
            AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
            receive.accept();
            assertNotNull(receive);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        receiver.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Wait.assertEquals(0, queueView::getMessageCount);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    connection.close();
    server.stop();
    server.start();
    queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) IOException(java.io.IOException) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 55 with AmqpMessage

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

the class AmqpReceiverDispositionTest method testRejectedDisposition.

@Test(timeout = 30000)
public void testRejectedDisposition() 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);
    assertEquals("MessageID:0", message.getMessageId());
    Message protonMessage = message.getWrappedMessage();
    assertNotNull(protonMessage);
    assertEquals("Unexpected initial value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
    message.reject();
    // Reject is a terminal outcome and should not be redelivered to the rejecting receiver
    // or any other as it should move to the archived state.
    receiver1.flow(1);
    message = receiver1.receiveNoWait();
    assertNull("Should not receive message again", message);
    // Attempt to Read the message again with another receiver to validate it is archived.
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    receiver2.flow(1);
    assertNull(receiver2.receiveNoWait());
    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)

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