Search in sources :

Example 21 with AmqpConnection

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

the class AmqpSendReceiveTest method doTestSendReceiveLotsOfDurableMessages.

private void doTestSendReceiveLotsOfDurableMessages(Class<?> destType) throws Exception {
    final int MSG_COUNT = 1000;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final CountDownLatch done = new CountDownLatch(MSG_COUNT);
    final AtomicBoolean error = new AtomicBoolean(false);
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final String address;
    if (Queue.class.equals(destType)) {
        address = getQueueName();
    } else {
        address = getTopicName();
    }
    final AmqpReceiver receiver = session.createReceiver(address);
    receiver.flow(MSG_COUNT);
    AmqpSender sender = session.createSender(address);
    Queue queueView = getProxyToQueue(address);
    executor.execute(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < MSG_COUNT; i++) {
                try {
                    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
                    received.accept();
                    done.countDown();
                } catch (Exception ex) {
                    LOG.info("Caught error: {}", ex.getClass().getSimpleName());
                    error.set(true);
                }
            }
        }
    });
    for (int i = 0; i < MSG_COUNT; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        sender.send(message);
    }
    assertTrue("did not read all messages, waiting on: " + done.getCount(), done.await(10, TimeUnit.SECONDS));
    assertFalse("should not be any errors on receive", error.get());
    Wait.assertEquals(0, queueView::getDeliveringCount);
    sender.close();
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ExecutorService(java.util.concurrent.ExecutorService) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 22 with AmqpConnection

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

the class AmqpSendReceiveTest method testTwoQueueReceiversOnSameConnectionReadMessagesNoDispositions.

@Test(timeout = 60000)
public void testTwoQueueReceiversOnSameConnectionReadMessagesNoDispositions() throws Exception {
    int MSG_COUNT = 4;
    sendMessages(getQueueName(), MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(MSG_COUNT, queueView.getMessageCount());
    receiver1.flow(2);
    assertNotNull(receiver1.receive(5, TimeUnit.SECONDS));
    assertNotNull(receiver1.receive(5, TimeUnit.SECONDS));
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    assertEquals(2, server.getTotalConsumerCount());
    receiver2.flow(2);
    assertNotNull(receiver2.receive(5, TimeUnit.SECONDS));
    assertNotNull(receiver2.receive(5, TimeUnit.SECONDS));
    assertEquals(0, queueView.getMessagesAcknowledged());
    receiver1.close();
    receiver2.close();
    assertEquals(MSG_COUNT, 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) Test(org.junit.Test)

Example 23 with AmqpConnection

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

the class AmqpSendReceiveTest method testDeliveryDelayOfferedWhenRequested.

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

        @Override
        public void inspectOpenedResource(Sender sender) {
            Symbol[] offered = sender.getRemoteOfferedCapabilities();
            if (!contains(offered, AmqpSupport.DELAYED_DELIVERY)) {
                markAsInvalid("Broker did not indicate it support delayed message delivery");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
    assertNotNull(sender);
    connection.getStateInspector().assertValid();
    sender.close();
    connection.close();
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 24 with AmqpConnection

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

the class AmqpSendReceiveTest method doTestMessageWithToFieldSet.

private void doTestMessageWithToFieldSet(boolean anonymous, String expected) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final String address = getQueueName();
    AmqpSender sender = session.createSender(anonymous ? null : address);
    AmqpMessage message = new AmqpMessage();
    message.setAddress(expected);
    message.setMessageId("msg:1");
    sender.send(message);
    AmqpReceiver receiver = session.createReceiver(address);
    Queue queueView = getProxyToQueue(address);
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    assertEquals(expected, received.getAddress());
    receiver.close();
    assertEquals(1, 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 25 with AmqpConnection

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

the class AmqpSenderTest method doTestReceiverSettlementModeForcedToFirst.

/*
    * The Broker does not currently support ReceiverSettleMode of SECOND so we ensure that it
    * always drops that back to FIRST to let the client know. The client will need to check and
    * react accordingly.
    */
private void doTestReceiverSettlementModeForcedToFirst(ReceiverSettleMode modeToUse) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender("queue://" + getTestName(), SenderSettleMode.UNSETTLED, modeToUse);
    Queue queueView = getProxyToQueue(getQueueName());
    assertNotNull(queueView);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(ReceiverSettleMode.FIRST, sender.getEndpoint().getRemoteReceiverSettleMode());
    sender.close();
    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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue)

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