Search in sources :

Example 41 with AmqpReceiver

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

the class AmqpDurableReceiverTest method testLookupExistingSubscriptionWithSelector.

@Test(timeout = 60000)
public void testLookupExistingSubscriptionWithSelector() 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(), SELECTOR_STRING, false);
    receiver.detach();
    receiver = session.lookupSubscription(getSubscriptionName());
    assertNotNull(receiver);
    Receiver protonReceiver = receiver.getReceiver();
    assertNotNull(protonReceiver.getRemoteSource());
    Source remoteSource = (Source) protonReceiver.getRemoteSource();
    assertNotNull(remoteSource.getFilter());
    assertFalse(remoteSource.getFilter().containsKey(NO_LOCAL_NAME));
    assertTrue(remoteSource.getFilter().containsKey(JMS_SELECTOR_NAME));
    String selector = (String) ((DescribedType) remoteSource.getFilter().get(JMS_SELECTOR_NAME)).getDescribed();
    assertEquals(SELECTOR_STRING, selector);
    assertEquals(TerminusExpiryPolicy.NEVER, remoteSource.getExpiryPolicy());
    assertEquals(TerminusDurability.UNSETTLED_STATE, remoteSource.getDurable());
    assertEquals(COPY, remoteSource.getDistributionMode());
    receiver.close();
    try {
        receiver = session.lookupSubscription(getSubscriptionName());
        fail("Should not be able to lookup the subscription");
    } catch (Exception e) {
    }
    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) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) Test(org.junit.Test)

Example 42 with AmqpReceiver

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

the class AmqpDurableReceiverTest method testCreateDurableReceiver.

@Test(timeout = 60000)
public void testCreateDurableReceiver() 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.flow(1);
    assertEquals(getTopicName(), lookupSubscription());
    AmqpSender sender = session.createSender(getTopicName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("message:1");
    sender.send(message);
    message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    connection.close();
    assertEquals(getTopicName(), lookupSubscription());
}
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) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 43 with AmqpReceiver

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

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

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

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