Search in sources :

Example 11 with AmqpSender

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

the class AmqpSendReceiveTest method doTestBrokerRestartAndDurability.

private void doTestBrokerRestartAndDurability(boolean durable, boolean enforceHeader) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    final Queue queueView1 = getProxyToQueue(getQueueName());
    // Create default message that should be sent as non-durable
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message -> non-durable");
    message.setMessageId("ID:Message:1");
    if (durable) {
        message.setDurable(true);
    } else {
        if (enforceHeader) {
            message.setDurable(false);
            assertNotNull(message.getWrappedMessage().getHeader());
        } else {
            assertNull(message.getWrappedMessage().getHeader());
        }
    }
    sender.send(message);
    connection.close();
    Wait.assertEquals(1, queueView1::getMessageCount);
    // Restart the server and the Queue should be empty
    server.stop();
    server.start();
    // Reconnect now
    connection = addConnection(client.connect());
    session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    final Queue queueView2 = getProxyToQueue(getQueueName());
    if (durable) {
        Wait.assertTrue("Message should not have returned", () -> queueView2.getMessageCount() == 1);
    } else {
        Wait.assertTrue("Message should have been restored", () -> queueView2.getMessageCount() == 0);
    }
    receiver.flow(1);
    message = receiver.receive(1, TimeUnit.SECONDS);
    if (durable) {
        assertNotNull("Should have read a message", message);
    } else {
        assertNull("Should not have read a message", message);
    }
    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) 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 12 with AmqpSender

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

the class AmqpSendReceiveTest method testReceiveMessageBeyondAckedAmountQueue.

@Test(timeout = 60000)
public void testReceiveMessageBeyondAckedAmountQueue() throws Exception {
    final int MSG_COUNT = 50;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final String address = getQueueName();
    AmqpReceiver receiver = session.createReceiver(address);
    AmqpSender sender = session.createSender(address);
    final Queue destinationView = getProxyToQueue(address);
    for (int i = 0; i < MSG_COUNT; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        sender.send(message);
    }
    List<AmqpMessage> pendingAcks = new ArrayList<>();
    for (int i = 0; i < MSG_COUNT; i++) {
        receiver.flow(1);
        AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
        assertNotNull(received);
        pendingAcks.add(received);
    }
    // Send one more to check in-flight stays at zero with no credit and all
    // pending messages settled.
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg-final");
    sender.send(message);
    for (AmqpMessage pendingAck : pendingAcks) {
        pendingAck.accept();
    }
    Wait.assertEquals(0, destinationView::getDeliveringCount);
    sender.close();
    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) ArrayList(java.util.ArrayList) 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) Test(org.junit.Test)

Example 13 with AmqpSender

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

the class AmqpSendReceiveTest method testSimpleSendOneReceiveOne.

@Test(timeout = 60000)
public void testSimpleSendOneReceiveOne() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg" + 1);
    message.setMessageAnnotation("serialNo", 1);
    message.setText("Test-Message");
    sender.send(message);
    sender.close();
    LOG.info("Attempting to read message with receiver");
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(2);
    AmqpMessage received = receiver.receive(10, TimeUnit.SECONDS);
    assertNotNull("Should have read message", received);
    assertEquals("msg1", received.getMessageId());
    received.accept();
    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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 14 with AmqpSender

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

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

Aggregations

AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)90 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)90 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)89 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)89 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)82 Test (org.junit.Test)74 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)61 Queue (org.apache.activemq.artemis.core.server.Queue)47 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 URI (java.net.URI)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)5 Sender (org.apache.qpid.proton.engine.Sender)5 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 Delivery (org.apache.qpid.proton.engine.Delivery)4 BytesMessage (javax.jms.BytesMessage)3