Search in sources :

Example 76 with AmqpClient

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

the class AmqpDurableReceiverTest method testDetachedDurableReceiverRemainsActive.

@Test(timeout = 60000)
public void testDetachedDurableReceiverRemainsActive() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.createConnection());
    connection.setContainerId(getContainerID());
    connection.connect();
    connection.setReceivedFrameInspector(new AmqpFrameValidator() {

        @Override
        public void inspectDetach(Detach detach, Binary encoded) {
            if (detach.getClosed()) {
                markAsInvalid("Remote should have detached but closed instead.");
            }
        }
    });
    connection.setSentFrameInspector(new AmqpFrameValidator() {

        @Override
        public void inspectDetach(Detach detach, Binary encoded) {
            if (detach.getClosed()) {
                markAsInvalid("Client should have detached but closed instead.");
            }
        }
    });
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createDurableReceiver(getTopicName(), getSubscriptionName());
    assertEquals(getTopicName(), lookupSubscription());
    receiver.detach();
    assertEquals(getTopicName(), lookupSubscription());
    connection.getSentFrameInspector().assertValid();
    connection.getReceivedFrameInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpFrameValidator(org.apache.activemq.transport.amqp.client.AmqpFrameValidator) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Binary(org.apache.qpid.proton.amqp.Binary) Detach(org.apache.qpid.proton.amqp.transport.Detach) Test(org.junit.Test)

Example 77 with AmqpClient

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

the class AmqpDurableReceiverTest method testReattachToDurableNode.

@Test(timeout = 60000)
public void testReattachToDurableNode() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.createConnection());
    connection.setContainerId(getContainerID());
    connection.connect();
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createDurableReceiver(getTopicName(), getSubscriptionName());
    receiver.detach();
    receiver = session.createDurableReceiver(getTopicName(), getSubscriptionName());
    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) Test(org.junit.Test)

Example 78 with AmqpClient

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

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

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

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)183 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)183 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)168 Test (org.junit.Test)158 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)114 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)91 Queue (org.apache.activemq.artemis.core.server.Queue)70 Source (org.apache.qpid.proton.amqp.messaging.Source)25 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)22 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 CountDownLatch (java.util.concurrent.CountDownLatch)8 Map (java.util.Map)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)7 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6