当前位置: 首页>>代码示例>>Java>>正文


Java JMSConsumer.close方法代码示例

本文整理汇总了Java中javax.jms.JMSConsumer.close方法的典型用法代码示例。如果您正苦于以下问题:Java JMSConsumer.close方法的具体用法?Java JMSConsumer.close怎么用?Java JMSConsumer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.JMSConsumer的用法示例。


在下文中一共展示了JMSConsumer.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sharedNonDurableUnsubscribeDifferentTopic

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void sharedNonDurableUnsubscribeDifferentTopic() throws Exception {
   context = cf.createContext();
   try {
      JMSConsumer con1 = context.createSharedConsumer(topic1, "mySharedCon");
      JMSConsumer con2 = context.createSharedConsumer(topic1, "mySharedCon");
      con1.close();
      Binding binding = server.getPostOffice().getBinding(new SimpleString("nonDurable.mySharedCon"));
      assertNotNull(binding);
      con2.close();
      binding = server.getPostOffice().getBinding(new SimpleString("nonDurable.mySharedCon"));
      assertNull(binding);
      con1 = context.createSharedConsumer(topic2, "mySharedCon");
   } finally {
      context.close();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:18,代码来源:SharedConsumerTest.java

示例2: testCloseMoreThanOnce

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testCloseMoreThanOnce() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue());

    consumer.close();
    consumer.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:8,代码来源:JmsPoolJMSConsumerTest.java

示例3: testReceive

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testReceive() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue());

    assertNull(consumer.receive());

    consumer.close();

    try {
        consumer.receive();
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateRuntimeException ise) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:14,代码来源:JmsPoolJMSConsumerTest.java

示例4: testReceiveNoWait

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testReceiveNoWait() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue());

    assertNull(consumer.receiveNoWait());

    consumer.close();

    try {
        consumer.receiveNoWait();
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateRuntimeException ise) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:14,代码来源:JmsPoolJMSConsumerTest.java

示例5: testReceiveTimed

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testReceiveTimed() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue());

    assertNull(consumer.receive(1));

    consumer.close();

    try {
        consumer.receive(1);
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateRuntimeException ise) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:14,代码来源:JmsPoolJMSConsumerTest.java

示例6: testGetMessageSelector

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testGetMessageSelector() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue(), "Color = Red");

    assertNotNull(consumer.getMessageSelector());
    assertEquals("Color = Red", consumer.getMessageSelector());

    consumer.close();

    try {
        consumer.getMessageSelector();
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateRuntimeException ise) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:15,代码来源:JmsPoolJMSConsumerTest.java

示例7: sharedDurableUnsubscribeNewTopic

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void sharedDurableUnsubscribeNewTopic() throws Exception {
   context = cf.createContext();
   try {
      JMSConsumer con1 = context.createSharedDurableConsumer(topic1, "mySharedCon");
      JMSConsumer con2 = context.createSharedDurableConsumer(topic1, "mySharedCon");
      con1.close();
      con2.close();
      context.unsubscribe("mySharedCon");
      con1 = context.createSharedDurableConsumer(topic2, "mySharedCon");
   } finally {
      context.close();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:15,代码来源:SharedConsumerTest.java

示例8: testSendAndReceiveOnAutoCreatedTopicJMS2

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSendAndReceiveOnAutoCreatedTopicJMS2() throws Exception {
   ConnectionFactory cf = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
   JMSContext context = cf.createContext();
   String topicName = UUID.randomUUID().toString();
   SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);

   try {
      Topic topic = context.createTopic(topicName);
      JMSProducer producer = context.createProducer();

      TextMessage message = context.createTextMessage("test-message");
      // this will auto-create the address, but not the subscription queue
      producer.send(topic, message);

      assertNotNull(server.getAddressInfo(simpleTopicName));
      assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType());
      assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated());
      assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());

      // this will auto-create the subscription queue
      JMSConsumer consumer = context.createConsumer(topic);
      assertFalse(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
      producer.send(topic, message);

      context.start();

      message = (TextMessage) consumer.receive(1000);

      assertNotNull(message);
      assertNotNull(message.getText());
      assertEquals("test-message", message.getText());
      consumer.close();
      assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
   } finally {
      context.close();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:39,代码来源:JMSTopicConsumerTest.java

示例9: closeQuietly

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
private void closeQuietly(JMSConsumer jmsConsumer) {
    if (jmsConsumer != null) {
        try {
            jmsConsumer.close();
        } catch (JMSRuntimeException ignored) {
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:9,代码来源:NewDataListener.java

示例10: createSubscription

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
/**
 * We create the subscription at soonest possible time after deployment so we
 * wouldn't miss any message
 */
@PostConstruct
void createSubscription() {
    try (JMSContext jms = factory.createContext()) { // <1> This is factory with clientId specified
        JMSConsumer consumer = jms.createDurableConsumer(topic, Resources.SUBSCRIPTION); // <2> creates durable subscription on the topic
        consumer.close();
    }
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:12,代码来源:SubscriptionCreator.java

示例11: testRemotelyCloseJMSConsumer

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test(timeout = 20000)
public void testRemotelyCloseJMSConsumer() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer);

        testPeer.expectBegin();

        // Create a consumer, then remotely end it afterwards.
        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlow();
        testPeer.remotelyDetachLastOpenedLinkOnLastOpenedSession(true, true, AmqpError.RESOURCE_DELETED, "resource closed");

        Queue queue = context.createQueue("myQueue");
        final JMSConsumer consumer = context.createConsumer(queue);

        // Verify the consumer gets marked closed
        testPeer.waitForAllHandlersToComplete(1000);
        assertTrue("JMSConsumer never closed.", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                try {
                    consumer.getMessageListener();
                } catch (IllegalStateRuntimeException jmsise) {
                    return true;
                }
                return false;
            }
        }, 10000, 10));

        // Try closing it explicitly, should effectively no-op in client.
        // The test peer will throw during close if it sends anything.
        consumer.close();

        testPeer.expectEnd();
        testPeer.expectClose();
        context.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:41,代码来源:JMSConsumerIntegrationTest.java

示例12: multipleSendsUsingSetters

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void multipleSendsUsingSetters() throws Exception {
   server.createQueue(SimpleString.toSimpleString("q1"), RoutingType.ANYCAST, SimpleString.toSimpleString("q1"), null, true, false);

   Queue q1 = context.createQueue("q1");

   context.createProducer().setProperty("prop1", 1).setProperty("prop2", 2).send(q1, "Text1");

   context.createProducer().setProperty("prop1", 3).setProperty("prop2", 4).send(q1, "Text2");

   for (int i = 0; i < 100; i++) {
      context.createProducer().send(q1, "Text" + i);
   }

   ActiveMQSession sessionUsed = (ActiveMQSession) (((ActiveMQJMSContext) context).getUsedSession());

   ClientSessionImpl coreSession = (ClientSessionImpl) sessionUsed.getCoreSession();

   // JMSConsumer is supposed to cache the producer, each call to createProducer is supposed to always return the same producer
   assertEquals(1, coreSession.cloneProducers().size());

   JMSConsumer consumer = context.createConsumer(q1);

   TextMessage text = (TextMessage) consumer.receive(5000);
   assertNotNull(text);
   assertEquals("Text1", text.getText());
   assertEquals(1, text.getIntProperty("prop1"));
   assertEquals(2, text.getIntProperty("prop2"));

   text = (TextMessage) consumer.receive(5000);
   assertNotNull(text);
   assertEquals("Text2", text.getText());
   assertEquals(3, text.getIntProperty("prop1"));
   assertEquals(4, text.getIntProperty("prop2"));

   for (int i = 0; i < 100; i++) {
      assertEquals("Text" + i, consumer.receiveBody(String.class, 1000));
   }

   consumer.close();
   context.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:43,代码来源:JmsProducerTest.java

示例13: testShareDuraleWithJMSContext

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@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);
      System.out.println("TXT:" + txt);
      Assert.assertNotNull(txt);

      txt = consumer.receiveBody(String.class, 5000);
      System.out.println("TXT:" + txt);
      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");

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:48,代码来源:JmsConsumerTest.java

示例14: testRollbackTest

import javax.jms.JMSConsumer; //导入方法依赖的package包/类
@Test
public void testRollbackTest() {
   JMSContext ctx = addContext(cf.createContext(JMSContext.SESSION_TRANSACTED));

   JMSProducer producer = ctx.createProducer();
   JMSConsumer cons = ctx.createConsumer(queue1);

   producer.send(queue1, context.createTextMessage("hello"));

   ctx.rollback();

   assertNull(cons.receiveNoWait());

   producer.send(queue1, context.createTextMessage("hello"));

   ctx.commit();

   assertNotNull(cons.receiveNoWait());

   ctx.commit();

   ctx.rollback();

   assertNull(cons.receiveNoWait());

   cons.close();

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:JmsContextTest.java


注:本文中的javax.jms.JMSConsumer.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。