Java Code Examples for javax.jms.JMSContext#createSharedDurableConsumer()

The following examples show how to use javax.jms.JMSContext#createSharedDurableConsumer() . 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: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testCreateSharedDurableConsumer() {
    JMSContext context = cf.createContext();
    Topic topic = context.createTopic(getTestName());
    assertNotNull(context.createSharedDurableConsumer(topic, "test"));

    context.close();
    try {
        context.createSharedDurableConsumer(topic, "test");
        fail("Should not be able to create resource when context is closed");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example 2
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testCreateSharedDurableConsumerWithSelector() {
    JMSContext context = cf.createContext();
    Topic topic = context.createTopic(getTestName());
    assertNotNull(context.createSharedDurableConsumer(topic, "test", "color = red"));

    context.close();
    try {
        context.createSharedDurableConsumer(topic, "test", "color = red");
        fail("Should not be able to create resource when context is closed");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example 3
Source File: JmsConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testShareDuraleWithJMSContext() throws Exception {
   ((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
   JMSContext conn = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);

   JMSConsumer consumer = conn.createSharedDurableConsumer(topic, "c1");

   JMSProducer producer = conn.createProducer();

   for (int i = 0; i < 100; i++) {
      producer.setProperty("count", i).send(topic, "test" + i);
   }

   JMSContext conn2 = conn.createContext(JMSContext.AUTO_ACKNOWLEDGE);
   JMSConsumer consumer2 = conn2.createSharedDurableConsumer(topic, "c1");

   for (int i = 0; i < 50; i++) {
      String txt = consumer.receiveBody(String.class, 5000);
      Assert.assertNotNull(txt);

      txt = consumer.receiveBody(String.class, 5000);
      Assert.assertNotNull(txt);
   }

   Assert.assertNull(consumer.receiveNoWait());
   Assert.assertNull(consumer2.receiveNoWait());

   boolean exceptionHappened = false;

   try {
      conn.unsubscribe("c1");
   } catch (Exception e) {
      e.printStackTrace();
      exceptionHappened = true;
   }

   Assert.assertTrue(exceptionHappened);

   consumer.close();
   consumer2.close();
   conn2.close();

   conn.unsubscribe("c1");

}