Search in sources :

Example 81 with AmqpClient

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

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

Example 83 with AmqpClient

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

the class AmqpReceiverTest method testReceiverCloseSendsRemoteClose.

@Test(timeout = 60000)
public void testReceiverCloseSendsRemoteClose() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    final AtomicBoolean closed = new AtomicBoolean();
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectClosedResource(Session session) {
            IntegrationTestLogger.LOGGER.info("Session closed: " + session.getContext());
        }

        @Override
        public void inspectDetachedResource(Receiver receiver) {
            markAsInvalid("Broker should not detach receiver linked to closed session.");
        }

        @Override
        public void inspectClosedResource(Receiver receiver) {
            IntegrationTestLogger.LOGGER.info("Receiver closed: " + receiver.getContext());
            closed.set(true);
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    assertNotNull(connection);
    AmqpSession session = connection.createSession();
    assertNotNull(session);
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    assertNotNull(receiver);
    receiver.close();
    assertTrue("Did not process remote close as expected", closed.get());
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Session(org.apache.qpid.proton.engine.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 84 with AmqpClient

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

the class AmqpReceiverTest method testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists.

@Test(timeout = 60000)
public void testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists() throws Exception {
    AddressSettings value = new AddressSettings();
    value.setAutoCreateQueues(false);
    value.setAutoCreateAddresses(false);
    server.getAddressSettingsRepository().addMatch("AnAddressThatDoesNotExist", value);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        Exception expectedException = null;
        try {
            session.createSender("AnAddressThatDoesNotExist");
            fail("Creating a sender here on an address that doesn't exist should fail");
        } catch (Exception e) {
            expectedException = e;
        }
        assertNotNull(expectedException);
        assertTrue(expectedException.getMessage().contains("amqp:not-found"));
        assertTrue(expectedException.getMessage().contains("target address does not exist"));
    } finally {
        connection.close();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 85 with AmqpClient

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

the class AmqpReceiverTest method testCreateQueueReceiverWithJMSSelector.

@Test(timeout = 60000)
public void testCreateQueueReceiverWithJMSSelector() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @SuppressWarnings("unchecked")
        @Override
        public void inspectOpenedResource(Receiver receiver) {
            if (receiver.getRemoteSource() == null) {
                markAsInvalid("Link opened with null source.");
            }
            Source source = (Source) receiver.getRemoteSource();
            Map<Symbol, Object> filters = source.getFilter();
            if (findFilter(filters, JMS_SELECTOR_FILTER_IDS) == null) {
                markAsInvalid("Broker did not return the JMS Filter on Attach");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    session.createReceiver(getQueueName(), "JMSPriority > 8");
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) HashMap(java.util.HashMap) Map(java.util.Map) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) 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