Example usage for javax.jms MessageProducer setDeliveryDelay

List of usage examples for javax.jms MessageProducer setDeliveryDelay

Introduction

In this page you can find the example usage for javax.jms MessageProducer setDeliveryDelay.

Prototype


void setDeliveryDelay(long deliveryDelay) throws JMSException;

Source Link

Document

Sets the minimum length of time in milliseconds that must elapse after a message is sent before the JMS provider may deliver the message to a consumer.

Usage

From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java

@Test
public void testScheduledStats() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();

    Connection connection = cf.createConnection();
    connection.start();/* w w  w  .j a  v a2  s . c  o m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName));
    producer.setDeliveryDelay(2000);
    producer.send(session.createTextMessage("test"));

    verifyPendingStats(defaultQueueName, 1, publishedMessageSize.get());
    verifyPendingDurableStats(defaultQueueName, 1, publishedMessageSize.get());
    verifyScheduledStats(defaultQueueName, 1, publishedMessageSize.get());

    consumeTestQueueMessages(1);

    verifyPendingStats(defaultQueueName, 0, 0);
    verifyPendingDurableStats(defaultQueueName, 0, 0);
    verifyScheduledStats(defaultQueueName, 0, 0);

    connection.close();
}