use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpExpiredMessageTest method testSendMessageThatIsExpiredUsingTTLWhenAbsoluteIsZero.
@Test(timeout = 60000)
public void testSendMessageThatIsExpiredUsingTTLWhenAbsoluteIsZero() 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(0);
// AET should override any TTL set
message.setTimeToLive(1000);
message.setText("Test-Message");
sender.send(message);
sender.close();
assertEquals(1, queueView.getMessageCount());
Thread.sleep(1000);
// 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();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpFlowControlTest method testCreditsAreRefreshedWhenAddressIsUnblocked.
@Test(timeout = 60000)
public void testCreditsAreRefreshedWhenAddressIsUnblocked() throws Exception {
fillAddress(getQueueName());
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
// Wait for a potential flow frame.
Thread.sleep(500);
assertEquals(0, sender.getSender().getCredit());
// Empty Address except for 1 message used later.
AmqpReceiver receiver = session.createReceiver(getQueueName());
receiver.flow(100);
AmqpMessage m;
for (int i = 0; i < messagesSent - 1; i++) {
m = receiver.receive(5000, TimeUnit.MILLISECONDS);
m.accept();
}
// Wait for address to unblock and flow frame to arrive
Thread.sleep(500);
assertTrue(sender.getSender().getCredit() >= 0);
} finally {
connection.close();
}
}
Aggregations