Search in sources :

Example 76 with AmqpSender

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

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

Example 78 with AmqpSender

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

the class AmqpScheduledMessageTest method testSendWithDeliveryTimeDeliversMessageAfterDelay.

@Test(timeout = 60000)
public void testSendWithDeliveryTimeDeliversMessageAfterDelay() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        AmqpMessage message = new AmqpMessage();
        long deliveryTime = System.currentTimeMillis() + 2000;
        message.setMessageAnnotation("x-opt-delivery-time", deliveryTime);
        message.setText("Test-Message");
        sender.send(message);
        // Now try and get the message
        receiver.flow(1);
        AmqpMessage received = receiver.receive(10, TimeUnit.SECONDS);
        assertNotNull(received);
        received.accept();
        Long msgDeliveryTime = (Long) received.getMessageAnnotation("x-opt-delivery-time");
        assertNotNull(msgDeliveryTime);
        assertEquals(deliveryTime, msgDeliveryTime.longValue());
    } 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) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 79 with AmqpSender

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

the class AmqpExpiredMessageTest method testSendMessageThatIsExiredUsingAbsoluteTimeWithLongTTL.

@Test(timeout = 60000)
public void testSendMessageThatIsExiredUsingAbsoluteTimeWithLongTTL() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    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();
    message.setAbsoluteExpiryTime(System.currentTimeMillis() - 5000);
    // AET should override any TTL set
    message.setTimeToLive(60000);
    message.setText("Test-Message");
    sender.send(message);
    sender.close();
    assertEquals(1, queueView.getMessageCount());
    // Now try and get the message
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage received = receiver.receiveNoWait();
    assertNull(received);
    Wait.assertEquals(1, queueView::getMessagesExpired);
    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 80 with AmqpSender

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

the class AmqpExpiredMessageTest method testSendMessageThatIsNotExpiredUsingTimeToLive.

@Test(timeout = 60000)
public void testSendMessageThatIsNotExpiredUsingTimeToLive() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    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();
    message.setTimeToLive(5000);
    message.setText("Test-Message");
    sender.send(message);
    sender.close();
    assertEquals(1, queueView.getMessageCount());
    // Now try and get the message
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    assertEquals(0, queueView.getMessagesExpired());
    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

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