Search in sources :

Example 91 with AmqpReceiver

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

the class AmqpReceiverTest method doTestSenderSettlementModeIsHonored.

public void doTestSenderSettlementModeIsHonored(SenderSettleMode settleMode) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver("queue://" + getTestName(), settleMode, ReceiverSettleMode.FIRST);
    Queue queueView = getProxyToQueue(getQueueName());
    assertNotNull(queueView);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(1, server.getTotalConsumerCount());
    assertEquals(settleMode, receiver.getEndpoint().getRemoteSenderSettleMode());
    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) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 92 with AmqpReceiver

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

the class AmqpReceiverTest 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();
    AmqpReceiver receiver = session.createReceiver("queue://" + getTestName(), SenderSettleMode.MIXED, modeToUse);
    Queue queueView = getProxyToQueue(getQueueName());
    assertNotNull(queueView);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(1, server.getTotalConsumerCount());
    assertEquals(ReceiverSettleMode.FIRST, receiver.getEndpoint().getRemoteReceiverSettleMode());
    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) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 93 with AmqpReceiver

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

the class AmqpScheduledMessageTest method testSendRecvWithDeliveryTime.

@Test(timeout = 60000)
public void testSendRecvWithDeliveryTime() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Get the Queue View early to avoid racing the delivery.
        final Queue queueView = getProxyToQueue(getQueueName());
        assertNotNull(queueView);
        AmqpMessage message = new AmqpMessage();
        long deliveryTime = System.currentTimeMillis() + 6000;
        message.setMessageAnnotation("x-opt-delivery-time", deliveryTime);
        message.setText("Test-Message");
        sender.send(message);
        sender.close();
        assertEquals(1, queueView.getScheduledCount());
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        receiver.flow(1);
        // Now try and get the message, should not due to being scheduled.
        AmqpMessage received = receiver.receive(2, TimeUnit.SECONDS);
        assertNull(received);
        // Now try and get the message, should get it now
        received = receiver.receive(10, TimeUnit.SECONDS);
        assertNotNull(received);
        received.accept();
    } finally {
        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) Test(org.junit.Test)

Example 94 with AmqpReceiver

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

the class AmqpScheduledMessageTest method testSendWithDeliveryTimeIsScheduled.

@Test(timeout = 60000)
public void testSendWithDeliveryTimeIsScheduled() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Get the Queue View early to avoid racing the delivery.
        final Queue queueView = getProxyToQueue(getQueueName());
        assertNotNull(queueView);
        AmqpMessage message = new AmqpMessage();
        long deliveryTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(2);
        message.setMessageAnnotation("x-opt-delivery-time", deliveryTime);
        message.setText("Test-Message");
        sender.send(message);
        sender.close();
        assertEquals(1, queueView.getScheduledCount());
        // Now try and get the message
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        receiver.flow(1);
        AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
        assertNull(received);
    } finally {
        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) Test(org.junit.Test)

Example 95 with AmqpReceiver

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

the class AmqpScheduledMessageTest method testScheduleWithDelay.

@Test(timeout = 60000)
public void testScheduleWithDelay() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Get the Queue View early to avoid racing the delivery.
        final Queue queueView = getProxyToQueue(getQueueName());
        assertNotNull(queueView);
        AmqpMessage message = new AmqpMessage();
        long delay = 6000;
        message.setMessageAnnotation("x-opt-delivery-delay", delay);
        message.setText("Test-Message");
        sender.send(message);
        sender.close();
        assertEquals(1, queueView.getScheduledCount());
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        receiver.flow(1);
        // Now try and get the message, should not due to being scheduled.
        AmqpMessage received = receiver.receive(2, TimeUnit.SECONDS);
        assertNull(received);
        // Now try and get the message, should get it now
        received = receiver.receive(10, TimeUnit.SECONDS);
        assertNotNull(received);
        received.accept();
    } finally {
        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) 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