Example usage for javax.jms Connection createSession

List of usage examples for javax.jms Connection createSession

Introduction

In this page you can find the example usage for javax.jms Connection createSession.

Prototype


Session createSession() throws JMSException;

Source Link

Document

Creates a Session object, specifying no arguments.

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  .j a va  2s .c  om*/

    // 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();
}