Example usage for javax.jms DeliveryMode PERSISTENT

List of usage examples for javax.jms DeliveryMode PERSISTENT

Introduction

In this page you can find the example usage for javax.jms DeliveryMode PERSISTENT.

Prototype

int PERSISTENT

To view the source code for javax.jms DeliveryMode PERSISTENT.

Click Source Link

Document

This delivery mode instructs the JMS provider to log the message to stable storage as part of the client's send operation.

Usage

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

@Test
public void testQueueMessageSizePersistentAndNonPersistent() throws Exception {

    AtomicLong publishedNonPersistentMessageSize = new AtomicLong();
    AtomicLong publishedMessageSize = new AtomicLong();

    publishTestQueueMessages(100, DeliveryMode.PERSISTENT, publishedMessageSize);
    publishTestQueueMessages(100, DeliveryMode.NON_PERSISTENT, publishedNonPersistentMessageSize);
    verifyPendingStats(defaultQueueName, 200,
            publishedMessageSize.get() + publishedNonPersistentMessageSize.get());
    verifyPendingDurableStats(defaultQueueName, 100, publishedMessageSize.get());
}

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

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

    Connection connection = cf.createConnection();
    connection.setClientID("clientId");
    connection.start();/*from ww  w .j a  va 2 s  .  co  m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createTopic(defaultTopicName));

    publishTestTopicMessages(100, DeliveryMode.NON_PERSISTENT, publishedNonPersistentMessageSize);
    publishTestTopicMessages(100, DeliveryMode.PERSISTENT, publishedMessageSize);

    verifyPendingStats(defaultTopicName, 200,
            publishedMessageSize.get() + publishedNonPersistentMessageSize.get());

    // consume all messages
    consumeTestMessages(consumer, 200);

    // All messages should now be gone
    verifyPendingStats(defaultTopicName, 0, 0);

    connection.close();
}

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

@Test
public void testMessageSizeOneDurable() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();
    Connection connection = cf.createConnection();
    connection.setClientID("clientId");
    connection.start();//  w  w w.  j  av  a  2  s .  c  om

    publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT, false);

    // verify the count and size - durable is offline so all 200 should be
    // pending since none are in prefetch
    verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get());

    // consume all messages
    consumeDurableTestMessages(connection, "sub1", 200, publishedMessageSize);

    // All messages should now be gone
    verifyPendingStats(defaultTopicName, 0, 0);
    verifyPendingDurableStats(defaultTopicName, 0, 0);

    connection.close();
}

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

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

    Connection connection = cf.createConnection();
    connection.setClientID("clientId");
    connection.start();/*w ww.j a  v  a2 s.com*/

    publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT, false);

    verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get());

    // consume partial messages
    consumeDurableTestMessages(connection, "sub1", 50, publishedMessageSize);

    // 150 should be left
    verifyPendingStats(defaultTopicName, 150, publishedMessageSize.get());
    // We don't really know the size here but it should be smaller than before
    // so take an average
    verifyPendingDurableStats(defaultTopicName, 150, (long) (.75 * publishedMessageSize.get()));

    connection.close();
}

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

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

    Connection connection = cf.createConnection();
    connection.setClientID("clientId");
    connection.start();/*from w  ww.  j a  v  a2 s. co m*/

    publishTestMessagesDurable(connection, new String[] { "sub1", "sub2" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT, false);

    // verify the count and size - double because two durables so two queue
    // bindings
    verifyPendingStats(defaultTopicName, 400, 2 * publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 400, 2 * publishedMessageSize.get());

    // consume messages just for sub1
    consumeDurableTestMessages(connection, "sub1", 200, publishedMessageSize);

    // There is still a durable that hasn't consumed so the messages should
    // exist
    verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get());

    connection.close();

    // restart and verify load
    this.killServer();
    this.restartServer();
    verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get());
}

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

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

    Connection connection = cf.createConnection();
    connection.setClientID("clientId");
    connection.start();/*from  ww w  .  j a v a  2 s .  c  o  m*/

    // The publish method will create a second shared consumer
    Session s = connection.createSession();
    MessageConsumer c = s.createSharedDurableConsumer(s.createTopic(defaultTopicName), "sub1");
    publishTestMessagesDurable(connection, new String[] { "sub1", }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT, true);

    // verify the count and size - double because two durables so two queue
    // bindings
    verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get());
    c.close();

    // consume messages for sub1
    consumeDurableTestMessages(connection, "sub1", 200, publishedMessageSize);
    verifyPendingStats(defaultTopicName, 0, publishedMessageSize.get());
    verifyPendingDurableStats(defaultTopicName, 0, publishedMessageSize.get());

    connection.close();
}

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

protected void publishTestTopicMessages(int publishSize, AtomicLong publishedMessageSize) throws Exception {
    publishTestTopicMessages(publishSize, DeliveryMode.PERSISTENT, publishedMessageSize);
}

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

protected void publishTestQueueMessagesTx(int count, AtomicLong publishedMessageSize) throws Exception {
    publishTestQueueMessages(count, defaultQueueName, DeliveryMode.PERSISTENT,
            JournalPendingMessageTest.maxMessageSize, publishedMessageSize, true);
}

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

protected void publishTestQueueMessages(int count, AtomicLong publishedMessageSize) throws Exception {
    publishTestQueueMessages(count, defaultQueueName, DeliveryMode.PERSISTENT,
            JournalPendingMessageTest.maxMessageSize, publishedMessageSize, false);
}

From source file:org.apache.activemq.broker.region.cursors.KahaDBPendingMessageCursorTest.java

/**
 * Test that the the counter restores size and works after restart and more
 * messages are published/*from w  w  w. j a va  2 s.c o  m*/
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testDurableMessageSizeAfterRestartAndPublish() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();

    Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
    connection.setClientID("clientId");
    connection.start();
    Topic topic = publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT);

    SubscriptionKey subKey = new SubscriptionKey("clientId", "sub1");

    // verify the count and size
    verifyPendingStats(topic, subKey, 200, publishedMessageSize.get());
    verifyStoreStats(topic, 200, publishedMessageSize.get());

    // stop, restart broker and publish more messages
    stopBroker();
    this.setUpBroker(false);

    connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
    connection.setClientID("clientId");
    connection.start();

    topic = publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT);

    // verify the count and size
    verifyPendingStats(topic, subKey, 400, publishedMessageSize.get());
    verifyStoreStats(topic, 400, publishedMessageSize.get());

}