Java Code Examples for javax.jms.TopicSubscriber#close()

The following examples show how to use javax.jms.TopicSubscriber#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsPoolTopicSubscriberTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetNoLocal() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
    TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTemporaryTopic();
    TopicSubscriber subscriber = session.createDurableSubscriber(topic, "name", "color = red", true);

    assertTrue(subscriber.getNoLocal());

    subscriber.close();

    try {
        subscriber.getNoLocal();
        fail("Cannot read state on closed subscriber");
    } catch (IllegalStateException ise) {}
}
 
Example 2
Source File: DurableSubscriptionRemoveOfflineTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testRemoveAfterRestart() throws Exception {
   Connection connection = createConnection();
   connection.setClientID("cliID");
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TopicSubscriber subscriber = session.createDurableSubscriber((Topic) createDestination(), "subName");
   subscriber.close();
   connection.close();

   LOG.info("Broker restarting, wait for inactive cleanup afterwards.");

   restartBroker();

   LOG.info("Broker restarted, wait for inactive cleanup now.");

   assertTrue(broker.getAdminView().getInactiveDurableTopicSubscribers().length == 1);

   assertTrue(Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         return broker.getAdminView().getInactiveDurableTopicSubscribers().length == 0;
      }
   }, 20000));
}
 
Example 3
Source File: DurableSubscriptionHangTestCase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private Message collectMessagesFromDurableSubscriptionForOneMinute() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
   TopicConnection connection = connectionFactory.createTopicConnection();

   connection.setClientID(clientID);
   TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = topicSession.createTopic(topicName);
   connection.start();
   TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, durableSubName);
   LOG.info("About to receive messages");
   Message message = subscriber.receive(120000);
   subscriber.close();
   connection.close();
   LOG.info("collectMessagesFromDurableSubscriptionForOneMinute done");

   return message;
}
 
Example 4
Source File: NetworkRemovesSubscriptionsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Running this test you can produce a leak of only 2 ConsumerInfo on BE
 * broker, NOT 200 as in other cases!
 */
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {

   TopicConnection connection = connectionFactory.createTopicConnection();
   connection.start();

   for (int i = 0; i < 100; i++) {
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
      DummyMessageListener listener = new DummyMessageListener();
      subscriber.setMessageListener(listener);
      if (i != 50) {
         subscriber.close();
         subscriberSession.close();
      }
   }

   connection.close();
   Thread.sleep(1000);
   Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
   assertNotNull(dest);
   assertTrue(dest.getConsumers().isEmpty());
}
 
Example 5
Source File: NetworkRemovesSubscriptionsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testWithOneSubscriber() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
      DummyMessageListener listener = new DummyMessageListener();
      subscriber.setMessageListener(listener);
      subscriber.close();
      subscriberSession.close();
      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());
   }
 
Example 6
Source File: DurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscribeWithActiveSubscription() throws Exception {
   Connection conn = createConnection();
   conn.setClientID("zeke");

   Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TopicSubscriber dursub1 = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");

   try {
      s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");
      ProxyAssertSupport.fail();
   } catch (IllegalStateException e) {
      // Ok - it is illegal to have more than one active subscriber on a subscrtiption at any one time
   }

   dursub1.close();

   s.unsubscribe("dursub1");
}
 
Example 7
Source File: NetworkRemovesSubscriptionsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testWithSessionAndSubsciberClose() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();

      for (int i = 0; i < 100; i++) {
         TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
         DummyMessageListener listener = new DummyMessageListener();
         subscriber.setMessageListener(listener);
         subscriber.close();
         subscriberSession.close();
      }
      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());
   }
 
Example 8
Source File: JmsPoolTopicSubscriberTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTopic() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
    TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTemporaryTopic();
    TopicSubscriber subscriber = session.createSubscriber(topic);

    assertNotNull(subscriber.getTopic());
    assertSame(topic, subscriber.getTopic());

    subscriber.close();

    try {
        subscriber.getTopic();
        fail("Cannot read topic on closed subscriber");
    } catch (IllegalStateException ise) {}
}
 
Example 9
Source File: BDBUpgradeTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void consumeDurableSubscriptionMessages(Connection connection, boolean selector) throws Exception
{
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = null;
    TopicSubscriber durSub = null;

    if (selector)
    {
        topic = session.createTopic(SELECTOR_TOPIC_NAME);
        durSub = session.createDurableSubscriber(topic, SELECTOR_SUB_NAME, "testprop='true'", false);
    }
    else
    {
        topic = session.createTopic(TOPIC_NAME);
        durSub = session.createDurableSubscriber(topic, SUB_NAME);
    }

    // Retrieve the matching message
    Message m = durSub.receive(getReceiveTimeout());
    assertThat("Failed to receive an expected message", m, is(notNullValue()));
    if (selector)
    {
        assertThat("Selector property did not match", m.getStringProperty("testprop"), is(equalTo("true")));
    }
    assertThat("ID property did not match", m.getIntProperty("ID"), is(equalTo(1)));
    assertThat("Message content was not as expected",
               ((TextMessage) m).getText(),
               is(equalTo(generateString(1024))));

    // Verify that no more messages are received
    m = durSub.receive(getReceiveTimeout());
    assertThat("No more messages should have been recieved", m, is(nullValue()));

    durSub.close();
    session.close();
}
 
Example 10
Source File: DurableSubscriptionHangTestCase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void registerDurableSubscription() throws JMSException {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
   TopicConnection connection = connectionFactory.createTopicConnection();
   connection.setClientID(clientID);
   TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = topicSession.createTopic(topicName);
   TopicSubscriber durableSubscriber = topicSession.createDurableSubscriber(topic, durableSubName);
   connection.start();
   durableSubscriber.close();
   connection.close();
   LOG.info("Durable Sub Registered");
}
 
Example 11
Source File: TopicDistributedTransactionTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Test
public void testPublisherWithRollback() throws Exception {

    String subscriptionId = "sub-testPublisherWithRollback";
    String topicName = "testPublisherWithRollback";
    String testMessage = "testPublisherWithRollback-Message";
    InitialContext initialContext = initialContextBuilder.withXaConnectionFactory().withTopic(topicName).build();
    Topic topic = (Topic) initialContext.lookup(topicName);

    // Setup XA producer.
    XATopicConnectionFactory xaTopicConnectionFactory =
            (XATopicConnectionFactory) initialContext.lookup(ClientHelper.XA_CONNECTION_FACTORY);
    XATopicConnection xaTopicConnection = xaTopicConnectionFactory.createXATopicConnection();
    XATopicSession xaTopicSession = xaTopicConnection.createXATopicSession();
    XAResource xaResource = xaTopicSession.getXAResource();
    MessageProducer producer = xaTopicSession.createProducer(topic);

    // Setup non-transactional consumer.
    TopicSession topicSession = xaTopicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
    TopicSubscriber durableSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId);
    xaTopicConnection.start();

    // Send message withing a XA transaction.
    XidImpl xid = new XidImpl(0, "branchId".getBytes(), "globalId".getBytes());
    xaResource.start(xid, XAResource.TMNOFLAGS);
    producer.send(xaTopicSession.createTextMessage(testMessage));
    xaResource.end(xid, XAResource.TMSUCCESS);

    int response = xaResource.prepare(xid);
    Assert.assertEquals(response, XAResource.XA_OK, "Prepare stage failed.");

    xaResource.rollback(xid);

    durableSubscriber.close();
    xaTopicSession.close();
    xaTopicConnection.close();
    QueueMetadata queueMetadata = restApiClient.getQueueMetadata("carbon:" + subscriptionId);
    Assert.assertEquals((int) queueMetadata.getSize(), 0, "Queue is not empty");
}
 
Example 12
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testDurableSubscriptionUnsubscribeInUseThrowsJMSEx() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);
        String subscriptionName = "mySubscription";

        testPeer.expectDurableSubscriberAttach(topicName, subscriptionName);
        testPeer.expectLinkFlow();

        TopicSubscriber subscriber = session.createDurableSubscriber(dest, subscriptionName);
        assertNotNull("TopicSubscriber object was null", subscriber);

        try {
            session.unsubscribe(subscriptionName);
            fail("Should have thrown a JMSException");
        } catch (JMSException ex) {
        }

        testPeer.expectDetach(false, true, false);

        subscriber.close();

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 13
Source File: ConsumerIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testCloseDurableTopicSubscriberDetachesWithCloseFalse() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);
        String subscriptionName = "mySubscription";

        testPeer.expectDurableSubscriberAttach(topicName, subscriptionName);
        testPeer.expectLinkFlow();

        TopicSubscriber subscriber = session.createDurableSubscriber(dest, subscriptionName);

        testPeer.expectDetach(false, true, false);
        subscriber.close();

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 14
Source File: DurableSubscriptionReactivationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testReactivateKeepaliveSubscription() throws Exception {

      Connection connection = createConnection();
      connection.setClientID("cliID");
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber subscriber = session.createDurableSubscriber((Topic) createDestination(), "subName");
      subscriber.close();
      connection.close();

      connection = createConnection();
      connection.start();
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(createDestination());
      producer.send(session.createMessage());
      connection.close();

      connection = createConnection();
      connection.setClientID("cliID");
      connection.start();
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      subscriber = session.createDurableSubscriber((Topic) createDestination(), "subName");
      Message message = subscriber.receive(1 * 1000);
      subscriber.close();
      connection.close();

      assertNotNull("Message not received.", message);
   }
 
Example 15
Source File: DurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDurableSubscriptionWithPeriodsInName() throws Exception {
   Connection conn = createConnection();
   conn.setClientID(".client.id.with.periods.");

   Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TopicSubscriber subscriber = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, ".subscription.name.with.periods.");

   s.createProducer(ActiveMQServerTestCase.topic1).send(s.createTextMessage("Subscription test"));

   conn.start();

   Message m = subscriber.receive(1000L);

   ProxyAssertSupport.assertNotNull(m);
   ProxyAssertSupport.assertTrue(m instanceof TextMessage);

   subscriber.close();

   s.unsubscribe(".subscription.name.with.periods.");
}
 
Example 16
Source File: AndesJMSConsumer.java    From product-ei with Apache License 2.0 4 votes vote down vote up
public void stopClientSync(){
    if (null != connection && null != session && null != receiver) {
        try {
            log.info("Closing Consumer");
            if (ExchangeType.TOPIC == consumerConfig.getExchangeType()) {
                if (null != receiver) {
                    TopicSubscriber topicSubscriber = (TopicSubscriber) receiver;
                    topicSubscriber.close();
                }

                if (null != session) {
                    TopicSession topicSession = (TopicSession) session;
                    topicSession.close();
                }

                if (null != connection) {
                    TopicConnection topicConnection = (TopicConnection) connection;
                    topicConnection.close();
                }
            } else if (ExchangeType.QUEUE == consumerConfig.getExchangeType()) {
                if (null != receiver) {
                    QueueReceiver queueReceiver = (QueueReceiver) receiver;
                    queueReceiver.close();
                }

                if (null != session) {
                    QueueSession queueSession = (QueueSession) session;
                    queueSession.close();
                }

                if (null != connection) {
                    QueueConnection queueConnection = (QueueConnection) connection;
                    queueConnection.stop();
                    queueConnection.close();
                }
            }

            receiver = null;
            session = null;
            connection = null;

            log.info("Consumer Closed");

        } catch (JMSException e) {
            log.error("Error in stopping client.", e);
            throw new RuntimeException("Error in stopping client.", e);
        }
    }
}
 
Example 17
Source File: DurableSubscribtionTest.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that messages are delivered normally to a subscriber on a separate connection despite
 * the use of durable subscriber with no-local on the first connection.
 */
@Test
public void testNoLocalSubscriberAndSubscriberOnSeparateConnection() throws Exception
{
    String noLocalSubscriptionName = getTestName() + "_no_local_sub";
    String subscriobtionName = getTestName() + "_sub";
    Topic topic = createTopic(getTestName());
    final String clientId = "clientId";

    Connection noLocalConnection = getConnectionBuilder().setClientId(clientId).build();
    try
    {
        Connection connection = getConnection();
        try
        {
            Session noLocalSession = noLocalConnection.createSession(true, Session.SESSION_TRANSACTED);
            Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

            MessageProducer noLocalSessionProducer = noLocalSession.createProducer(topic);
            MessageProducer sessionProducer = session.createProducer(topic);

            try
            {
                TopicSubscriber noLocalSubscriber =
                        noLocalSession.createDurableSubscriber(topic, noLocalSubscriptionName, null, true);
                TopicSubscriber subscriber = session.createDurableSubscriber(topic, subscriobtionName, null, false);
                noLocalConnection.start();
                connection.start();

                noLocalSessionProducer.send(noLocalSession.createTextMessage("Message1"));
                noLocalSession.commit();
                sessionProducer.send(session.createTextMessage("Message2"));
                sessionProducer.send(session.createTextMessage("Message3"));
                session.commit();

                Message durableSubscriberMessage = noLocalSubscriber.receive(getReceiveTimeout());
                assertTrue(durableSubscriberMessage instanceof TextMessage);
                assertEquals("Unexpected local message received",
                             "Message2",
                             ((TextMessage) durableSubscriberMessage).getText());
                noLocalSession.commit();

                Message nonDurableSubscriberMessage = subscriber.receive(getReceiveTimeout());
                assertTrue(nonDurableSubscriberMessage instanceof TextMessage);
                assertEquals("Unexpected message received",
                             "Message1",
                             ((TextMessage) nonDurableSubscriberMessage).getText());

                session.commit();
                noLocalSubscriber.close();
                subscriber.close();
            }
            finally
            {
                noLocalSession.unsubscribe(noLocalSubscriptionName);
                session.unsubscribe(subscriobtionName);
            }
        }
        finally
        {
            connection.close();
        }
    }
    finally
    {
        noLocalConnection.close();
    }
}
 
Example 18
Source File: DurableSubscribtionTest.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testUnsubscribe() throws Exception
{
    Topic topic = createTopic(getTestName());
    String subscriptionName = getTestName() + "_sub";
    String clientId = "clientId";
    int numberOfQueuesBeforeTest = getQueueCount();

    Connection connection = getConnectionBuilder().setClientId(clientId).build();
    try
    {
        Session durableSubscriberSession = connection.createSession(true, Session.SESSION_TRANSACTED);
        Session nonDurableSubscriberSession = connection.createSession(true, Session.SESSION_TRANSACTED);
        Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        MessageConsumer subscriber = nonDurableSubscriberSession.createConsumer(topic);
        MessageProducer producer = producerSession.createProducer(topic);
        TopicSubscriber durableSubscriber =
                durableSubscriberSession.createDurableSubscriber(topic, subscriptionName);

        connection.start();
        producer.send(nonDurableSubscriberSession.createTextMessage("A"));

        Message message = subscriber.receive(getReceiveTimeout());
        assertTrue(message instanceof TextMessage);
        assertEquals("A", ((TextMessage) message).getText());

        message = durableSubscriber.receive(getReceiveTimeout());
        assertTrue(message instanceof TextMessage);
        assertEquals("A", ((TextMessage) message).getText());

        nonDurableSubscriberSession.commit();
        durableSubscriberSession.commit();

        durableSubscriber.close();
        durableSubscriberSession.unsubscribe(subscriptionName);

        producer.send(nonDurableSubscriberSession.createTextMessage("B"));

        Session durableSubscriberSession2 = connection.createSession(true, Session.SESSION_TRANSACTED);
        TopicSubscriber durableSubscriber2 =
                durableSubscriberSession2.createDurableSubscriber(topic, subscriptionName);

        producer.send(nonDurableSubscriberSession.createTextMessage("C"));

        message = subscriber.receive(getReceiveTimeout());
        assertTrue(message instanceof TextMessage);
        assertEquals("B", ((TextMessage) message).getText());

        message = subscriber.receive(getReceiveTimeout());
        assertTrue(message instanceof TextMessage);
        assertEquals("C", ((TextMessage) message).getText());

        message = durableSubscriber2.receive(getReceiveTimeout());
        assertTrue(message instanceof TextMessage);
        assertEquals("C", ((TextMessage) message).getText());

        nonDurableSubscriberSession.commit();
        durableSubscriberSession2.commit();

        assertEquals("Message count should be 0", 0, getTotalDepthOfQueuesMessages());

        durableSubscriber2.close();
        durableSubscriberSession2.unsubscribe(subscriptionName);
    }
    finally
    {
        connection.close();
    }

    int numberOfQueuesAfterTest = getQueueCount();
    assertEquals("Unexpected number of queues", numberOfQueuesBeforeTest, numberOfQueuesAfterTest);
}
 
Example 19
Source File: DurableSubInBrokerNetworkTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testTwoDurableSubsInNetworkWithUnsubscribe() throws Exception {

      // create 1st durable sub to topic TEST.FOO
      ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory(connector.getConnectUri().toString());
      Connection conn = fact.createConnection();
      conn.setClientID("clientID1");
      Session session = conn.createSession(false, 1);
      Destination dest = session.createTopic(topicName);
      TopicSubscriber sub = session.createDurableSubscriber((Topic) dest, subName);
      LOG.info("Durable subscription of name " + subName + "created.");
      TopicSubscriber sub2 = session.createDurableSubscriber((Topic) dest, subName2);
      LOG.info("Durable subscription of name " + subName2 + "created.");

      Thread.sleep(100);

      // query durable sub on local and remote broker
      // raise an error if not found

      assertTrue(foundSubInLocalBroker(subName));
      assertTrue(foundSubInLocalBroker(subName2));

      assertTrue(foundSubInRemoteBrokerByTopicName(topicName));

      // unsubscribe from durable sub
      sub.close();
      session.unsubscribe(subName);
      LOG.info("Unsubscribed from durable subscription.");
      Thread.sleep(100);

      // query durable sub on local and remote broker
      assertFalse(foundSubInLocalBroker(subName));
      assertTrue(foundSubInLocalBroker(subName2));

      assertTrue("Durable subscription should still be on remote broker", foundSubInRemoteBrokerByTopicName(topicName));

      sub2.close();
      session.unsubscribe(subName2);

      Thread.sleep(100);

      assertFalse(foundSubInLocalBroker(subName2));

      assertFalse("Durable subscription not unregistered on remote broker", foundSubInRemoteBrokerByTopicName(topicName));

   }
 
Example 20
Source File: JmsDurableSubscriberTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testOfflineSubscriberGetsItsMessages() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();

    assertEquals(0, brokerService.getAdminView().getDurableTopicSubscribers().length);
    assertEquals(0, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);

    final int MSG_COUNT = 5;

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Topic topic = session.createTopic(name.getMethodName());
    TopicSubscriber subscriber = session.createDurableSubscriber(topic, getSubscriptionName());

    TopicViewMBean proxy = getProxyToTopic(name.getMethodName());
    assertEquals(0, proxy.getQueueSize());
    assertEquals(1, brokerService.getAdminView().getDurableTopicSubscribers().length);
    assertEquals(0, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);

    subscriber.close();

    assertEquals(0, brokerService.getAdminView().getDurableTopicSubscribers().length);
    assertEquals(1, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);

    MessageProducer producer = session.createProducer(topic);
    for (int i = 0; i < MSG_COUNT; i++) {
        producer.send(session.createTextMessage("Message: " + i));
    }
    producer.close();

    LOG.info("Bringing offline subscription back online.");
    subscriber = session.createDurableSubscriber(topic, getSubscriptionName());

    assertEquals(1, brokerService.getAdminView().getDurableTopicSubscribers().length);
    assertEquals(0, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);

    final CountDownLatch messages = new CountDownLatch(MSG_COUNT);
    subscriber.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("Consumer got a message: {}", message);
            messages.countDown();
        }
    });

    assertTrue("Only recieved messages: " + messages.getCount(), messages.await(30, TimeUnit.SECONDS));

    subscriber.close();

    session.unsubscribe(getSubscriptionName());
}