Example usage for javax.jms Session createSharedDurableConsumer

List of usage examples for javax.jms Session createSharedDurableConsumer

Introduction

In this page you can find the example usage for javax.jms Session createSharedDurableConsumer.

Prototype

MessageConsumer createSharedDurableConsumer(Topic topic, String name) throws JMSException;

Source Link

Document

Creates a shared durable subscription on the specified topic (if one does not already exist), specifying a message selector and the noLocal parameter, and creates a consumer on that durable subscription.

Usage

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();// ww w  .ja  v  a 2s.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();
}