Java Code Examples for javax.jms.Session#createDurableSubscriber()

The following examples show how to use javax.jms.Session#createDurableSubscriber() . 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: DurableUnsubscribeTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testUnsubscribe() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId");
   session.close();

   Destination d = broker.getDestination(topic);
   assertEquals("Subscription is missing.", 1, d.getConsumers().size());

   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(topic);
   for (int i = 0; i < 1000; i++) {
      producer.send(session.createTextMessage("text"));
   }

   Thread.sleep(1000);

   session.unsubscribe("SubsId");
   session.close();

   assertEquals("Subscription exists.", 0, d.getConsumers().size());
}
 
Example 2
Source File: AbstractPersistentStatTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void consumeDurableTestMessages(Connection connection, String sub, int size, String topicName,
      AtomicLong publishedMessageSize) throws Exception {


   Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
   Topic topic = session.createTopic(topicName);

   try {
      TopicSubscriber consumer = session.createDurableSubscriber(topic, sub);
      for (int i = 0; i < size; i++) {
         ActiveMQMessage message = (ActiveMQMessage) consumer.receive();
         if (publishedMessageSize != null) {
            publishedMessageSize.addAndGet(-message.getCoreMessage().getEncodeSize());
         }
      }

   } finally {
      session.close();
   }

}
 
Example 3
Source File: JmsRedeliveredTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testNoReceiveDurableConsumerDoesNotIncrementRedelivery() throws Exception {
   connection.setClientID(getName());
   connection.start();

   Session session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
   Topic topic = session.createTopic("topic-" + getName());
   MessageConsumer consumer = session.createDurableSubscriber(topic, "sub");

   MessageProducer producer = createProducer(session, topic);
   producer.send(createTextMessage(session));
   session.commit();

   TimeUnit.SECONDS.sleep(1);
   consumer.close();

   consumer = session.createDurableSubscriber(topic, "sub");
   Message msg = consumer.receive(1000);
   assertNotNull(msg);

   assertFalse("Message should not be redelivered.", msg.getJMSRedelivered());

   session.commit();
   session.close();
}
 
Example 4
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 5
Source File: JmsMultipleBrokersTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public MessageConsumer createDurableSubscriber(Topic dest, Session sess, String name) throws Exception {
   MessageConsumer client = sess.createDurableSubscriber(dest, name);
   MessageIdList messageIdList = new MessageIdList();
   messageIdList.setParent(allMessages);
   client.setMessageListener(messageIdList);
   consumers.put(client, messageIdList);

   return client;
}
 
Example 6
Source File: JmsRedeliveredTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests session recovery and that the redelivered message is marked as
 * such. Session uses client acknowledgement, the destination is a topic and
 * the consumer is a durable suscriber.
 *
 * @throws JMSException
 */
public void testDurableTopicRecoverMarksMessageRedelivered() throws JMSException {
   connection.setClientID(getName());
   connection.start();

   Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   Topic topic = session.createTopic("topic-" + getName());
   MessageConsumer consumer = session.createDurableSubscriber(topic, "sub1");

   MessageProducer producer = createProducer(session, topic);
   producer.send(createTextMessage(session));

   // Consume the message...
   Message msg = consumer.receive(1000);
   assertNotNull(msg);
   assertFalse("Message should not be redelivered.", msg.getJMSRedelivered());
   // Don't ack the message.

   // Reset the session. This should cause the Unacked message to be
   // redelivered.
   session.recover();

   // Attempt to Consume the message...
   msg = consumer.receive(2000);
   assertNotNull(msg);
   assertTrue("Message should be redelivered.", msg.getJMSRedelivered());
   msg.acknowledge();

   session.close();
}
 
Example 7
Source File: JMSConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testDurableConsumerSelectorChange() throws Exception {

      // Receive a message with the JMS API
      connection.setClientID("test");
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      destination = createDestination(session, destinationType);
      MessageProducer producer = session.createProducer(destination);
      producer.setDeliveryMode(deliveryMode);
      MessageConsumer consumer = session.createDurableSubscriber((Topic) destination, "test", "color='red'", false);

      // Send the messages
      TextMessage message = session.createTextMessage("1st");
      message.setStringProperty("color", "red");
      producer.send(message);

      Message m = consumer.receive(1000);
      assertNotNull(m);
      assertEquals("1st", ((TextMessage) m).getText());

      // Change the subscription.
      consumer.close();
      consumer = session.createDurableSubscriber((Topic) destination, "test", "color='blue'", false);

      message = session.createTextMessage("2nd");
      message.setStringProperty("color", "red");
      producer.send(message);
      message = session.createTextMessage("3rd");
      message.setStringProperty("color", "blue");
      producer.send(message);

      // Selector should skip the 2nd message.
      m = consumer.receive(1000);
      assertNotNull(m);
      assertEquals("3rd", ((TextMessage) m).getText());

      assertNull(consumer.receiveNoWait());
   }
 
Example 8
Source File: JMSDurableConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testDurableConsumerLarge() throws Exception {
   String durableClientId = getTopicName() + "-ClientId";

   Connection connection = createConnection(durableClientId);
   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(getTopicName());
      final MessageConsumer consumer1 = session.createDurableSubscriber(topic, "DurbaleSub1");
      final MessageConsumer consumer2 = session.createDurableSubscriber(topic, "DurbaleSub2");
      MessageProducer producer = session.createProducer(topic);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);
      connection.start();

      ObjectMessage objMessage = session.createObjectMessage();
      BigObject bigObject = new BigObject(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
      objMessage.setObject(bigObject);
      producer.send(objMessage);

      ObjectMessage msg1 = (ObjectMessage)consumer1.receive(5000);
      Assert.assertNotNull(msg1);
      assertTrue("Should be an instance of TextMessage", msg1 instanceof ObjectMessage);

      ObjectMessage msg2 = (ObjectMessage)consumer2.receive(5000);
      assertNotNull("Should have received a message by now.", msg2);
      assertTrue("Should be an instance of TextMessage", msg2 instanceof ObjectMessage);
   } finally {
      connection.close();
   }
}
 
Example 9
Source File: PollingMessageListenerContainer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private MessageConsumer createConsumer(Destination destination, Session session) throws JMSException {
    if (durableSubscriptionName != null && destination instanceof Topic) {
        return session.createDurableSubscriber((Topic)destination, durableSubscriptionName,
                                               messageSelector, pubSubNoLocal);
    }
    return session.createConsumer(destination, messageSelector);
}
 
Example 10
Source File: PerfConsumer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public PerfConsumer(ConnectionFactory fac, Destination dest, String consumerName) throws JMSException {
   connection = fac.createConnection();
   connection.setClientID(consumerName);
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   if (dest instanceof Topic && consumerName != null && consumerName.length() > 0) {
      consumer = s.createDurableSubscriber((Topic) dest, consumerName);
   } else {
      consumer = s.createConsumer(dest);
   }
   consumer.setMessageListener(this);
}
 
Example 11
Source File: DurableSubSelectorDelayTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void process() throws JMSException {
   long end = System.currentTimeMillis() + 20000;
   int transCount = 0;

   LOG.info(toString() + " ONLINE.");
   Connection con = openConnection();

   Session sess = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = sess.createDurableSubscriber(topic, subName, selector, false);

   try {

      do {
         long max = end - System.currentTimeMillis();

         if (max <= 0) {
            break;
         }

         Message message = consumer.receive(max);
         if (message == null) {
            continue;
         }

         LOG.info("Received Trans[id=" + message.getIntProperty("TRANS") + ", count=" + transCount + "] in " + this + ".");

      } while (true);

   } finally {
      sess.close();
      con.close();

      LOG.info(toString() + " OFFLINE.");
   }
}
 
Example 12
Source File: DurableSubProcessConcurrentCommitActivateNoDuplicateTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void subscribe() throws JMSException {
   processLock.readLock().lock();
   try {
      Connection con = openConnection();
      Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
      session.createDurableSubscriber(topic, SUBSCRIPTION_NAME, selector, true);
      session.close();
      con.close();
   } finally {
      processLock.readLock().unlock();
   }
}
 
Example 13
Source File: JMSDurableConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testDurableConsumerUnsubscribe() throws Exception {
   String durableClientId = getTopicName() + "-ClientId";

   Connection connection = createConnection(durableClientId);
   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(getTopicName());
      MessageConsumer consumer = session.createDurableSubscriber(topic, "DurbaleTopic");

      assertTrue(Wait.waitFor(new Wait.Condition() {

         @Override
         public boolean isSatisfied() throws Exception {
            return server.getTotalConsumerCount() == 1;
         }
      }, TimeUnit.SECONDS.toMillis(20), TimeUnit.MILLISECONDS.toMillis(250)));

      consumer.close();

      assertTrue(Wait.waitFor(new Wait.Condition() {

         @Override
         public boolean isSatisfied() throws Exception {
            return server.getTotalConsumerCount() == 0;
         }
      }, TimeUnit.SECONDS.toMillis(20), TimeUnit.MILLISECONDS.toMillis(250)));

      session.unsubscribe("DurbaleTopic");
      assertTrue(Wait.waitFor(new Wait.Condition() {

         @Override
         public boolean isSatisfied() throws Exception {
            return server.getTotalConsumerCount() == 0;
         }
      }, TimeUnit.SECONDS.toMillis(20), TimeUnit.MILLISECONDS.toMillis(250)));
   } finally {
      connection.close();
   }
}
 
Example 14
Source File: DurableSubscriptionActivationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testActivateWithExistingTopic() throws Exception {
   // create durable subscription
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId");

   Destination d = broker.getDestination(topic);
   assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);

   // restart the broker
   restartBroker();

   d = broker.getDestination(topic);
   assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);

   // activate
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId");

   assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);

   // re-activate
   connection.close();
   connection = createConnection();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId");

   assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);
}
 
Example 15
Source File: DurableSubscriptionOffline1Test.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testOfflineSubscriptionCanConsumeAfterOnlineSubs() throws Exception {
   Connection con = createConnection("offCli1");
   Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   session.close();
   con.close();

   con = createConnection("offCli2");
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   session.close();
   con.close();

   Connection con2 = createConnection("onlineCli1");
   Session session2 = con2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer2 = session2.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   DurableSubscriptionOfflineTestListener listener2 = new DurableSubscriptionOfflineTestListener();
   consumer2.setMessageListener(listener2);

   // send messages
   con = createConnection();
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(null);

   int sent = 0;
   for (int i = 0; i < 10; i++) {
      sent++;
      Message message = session.createMessage();
      message.setStringProperty("filter", "true");
      producer.send(topic, message);
   }

   Thread.sleep(1 * 1000);
   session.close();
   con.close();

   // test online subs
   Thread.sleep(3 * 1000);
   session2.close();
   con2.close();
   assertEquals(sent, listener2.count);

   // restart broker
   broker.stop();
   createBroker(false /*deleteAllMessages*/);

   // test offline
   con = createConnection("offCli1");
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);

   Connection con3 = createConnection("offCli2");
   Session session3 = con3.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer3 = session3.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);

   DurableSubscriptionOfflineTestListener listener = new DurableSubscriptionOfflineTestListener();
   consumer.setMessageListener(listener);
   DurableSubscriptionOfflineTestListener listener3 = new DurableSubscriptionOfflineTestListener();
   consumer3.setMessageListener(listener3);

   Thread.sleep(3 * 1000);

   session.close();
   con.close();
   session3.close();
   con3.close();

   assertEquals(sent, listener.count);
   assertEquals(sent, listener3.count);
}
 
Example 16
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 17
Source File: TopicDurableTests.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testMessageDurableSubscription() throws Exception {
   JmsConnectionFactory connectionFactory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI() + "?jms.clientID=jmsTopicClient");
   Connection connection = connectionFactory.createConnection();
   connection.start();

   instanceLog.debug("testMessageDurableSubscription");
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic testTopic =  session.createTopic("jmsTopic");

   String sub1ID = "sub1DurSub";
   String sub2ID = "sub2DurSub";
   MessageConsumer subscriber1 = session.createDurableSubscriber(testTopic, sub1ID);
   MessageConsumer subscriber2 = session.createDurableSubscriber(testTopic, sub2ID);
   MessageProducer messageProducer = session.createProducer(testTopic);

   int count = 100;
   String batchPrefix = "First";
   List<Message> listMsgs = generateMessages(session, batchPrefix, count);
   sendMessages(messageProducer, listMsgs);
   instanceLog.debug("First batch messages sent");

   List<Message> recvd1 = receiveMessages(subscriber1, count);
   List<Message> recvd2 = receiveMessages(subscriber2, count);

   assertThat(recvd1.size(), is(count));
   assertMessageContent(recvd1, batchPrefix);
   instanceLog.debug(sub1ID + " :First batch messages received");

   assertThat(recvd2.size(), is(count));
   assertMessageContent(recvd2, batchPrefix);
   instanceLog.debug(sub2ID + " :First batch messages received");

   subscriber1.close();
   instanceLog.debug(sub1ID + " : closed");

   batchPrefix = "Second";
   listMsgs = generateMessages(session, batchPrefix, count);
   sendMessages(messageProducer, listMsgs);
   instanceLog.debug("Second batch messages sent");

   recvd2 = receiveMessages(subscriber2, count);
   assertThat(recvd2.size(), is(count));
   assertMessageContent(recvd2, batchPrefix);
   instanceLog.debug(sub2ID + " :Second batch messages received");

   subscriber1 = session.createDurableSubscriber(testTopic, sub1ID);
   instanceLog.debug(sub1ID + " :connected");

   recvd1 = receiveMessages(subscriber1, count);
   assertThat(recvd1.size(), is(count));
   assertMessageContent(recvd1, batchPrefix);
   instanceLog.debug(sub1ID + " :Second batch messages received");

   subscriber1.close();
   subscriber2.close();

   session.unsubscribe(sub1ID);
   session.unsubscribe(sub2ID);
}
 
Example 18
Source File: DurableSubscriptionOffline1Test.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testConsumeOnlyMatchedMessages() throws Exception {
   // create durable subscription
   Connection con = createConnection();
   Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   session.close();
   con.close();

   // send messages
   con = createConnection();
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(null);

   int sent = 0;
   for (int i = 0; i < 10; i++) {
      boolean filter = i % 2 == 1;
      if (filter)
         sent++;

      Message message = session.createMessage();
      message.setStringProperty("filter", filter ? "true" : "false");
      producer.send(topic, message);
   }

   session.close();
   con.close();

   // consume messages
   con = createConnection();
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   DurableSubscriptionOfflineTestListener listener = new DurableSubscriptionOfflineTestListener();
   consumer.setMessageListener(listener);

   Thread.sleep(3 * 1000);

   session.close();
   con.close();

   assertEquals(sent, listener.count);
}
 
Example 19
Source File: DurableSubsOfflineSelectorIndexUseTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testIndexPageUsage() throws Exception {
   Connection con = createConnection();
   Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
   session.close();

   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
   session.close();

   con.close();

   // send messages
   final Connection sendCon = createConnection("send");
   final Session sendSession = sendCon.createSession(false, Session.AUTO_ACKNOWLEDGE);
   final MessageProducer producer = sendSession.createProducer(null);

   Thread sendThread = new Thread() {
      @Override
      public void run() {
         try {

            for (int i = 0; i < messageCount; i++) {
               boolean filter = i % 2 == 1;
               Message message = sendSession.createMessage();
               message.setStringProperty("filter", filter ? "true" : "false");
               producer.send(topic, message);

               if (i > 0 && i % 1000 == 0) {
                  LOG.info("Sent:" + i);
               }
            }
            sendSession.close();
            sendCon.close();
         } catch (Exception e) {
            exceptions.add(e);
         }
      }
   };
   sendThread.start();

   sendThread.join();

   // settle with sent messages
   TimeUnit.SECONDS.sleep(4);

   // consume messages
   con = createConnection();
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageConsumer consumerTrue = session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
   Listener listenerT = new Listener();
   consumerTrue.setMessageListener(listenerT);

   waitFor(listenerT, messageCount / 2);

   MessageConsumer consumerFalse = session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
   Listener listenerF = new Listener();
   consumerFalse.setMessageListener(listenerF);

   waitFor(listenerF, messageCount / 2);

   assertEquals(messageCount / 2, listenerT.count);
   assertEquals(messageCount / 2, listenerF.count);

   consumerTrue.close();
   session.unsubscribe("true");

   consumerFalse.close();
   session.unsubscribe("false");

   session.close();
   con.close();

   PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
   if (persistenceAdapter instanceof KahaDBPersistenceAdapter) {
      final KahaDBStore store = ((KahaDBPersistenceAdapter) persistenceAdapter).getStore();
      LOG.info("Store page count: " + store.getPageFile().getPageCount());
      LOG.info("Store free page count: " + store.getPageFile().getFreePageCount());
      LOG.info("Store page in-use: " + (store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount()));

      assertTrue("no leak of pages, always use just 10", Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            return 10 == store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount();
         }
      }, TimeUnit.SECONDS.toMillis(10)));
   }
}
 
Example 20
Source File: DurableSubscriptionOfflineTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60 * 1000)
public void testInterleavedOfflineSubscriptionCanConsumeAfterUnsub() throws Exception {
   // create offline subs 1
   Connection con = createConnection("offCli1");
   Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
   session.close();
   con.close();

   // create offline subs 2
   con = createConnection("offCli2");
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createDurableSubscriber(topic, "SubsId", null, true);
   session.close();
   con.close();

   // send messages
   con = createConnection();
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(null);

   int sent = 0;
   for (int i = 0; i < 10; i++) {
      boolean filter = (int) (Math.random() * 2) >= 1;

      sent++;

      Message message = session.createMessage();
      message.setStringProperty("filter", filter ? "true" : "false");
      producer.send(topic, message);
   }

   Thread.sleep(1 * 1000);

   Connection con2 = createConnection("offCli1");
   Session session2 = con2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   session2.unsubscribe("SubsId");
   session2.close();
   con2.close();

   // consume all messages
   con = createConnection("offCli2");
   session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
   DurableSubscriptionOfflineTestListener listener = new DurableSubscriptionOfflineTestListener("SubsId");
   consumer.setMessageListener(listener);

   Thread.sleep(3 * 1000);

   session.close();
   con.close();

   assertEquals("offline consumer got all", sent, listener.count);
}