當前位置: 首頁>>代碼示例>>Java>>正文


Java TopicSubscriber.close方法代碼示例

本文整理匯總了Java中javax.jms.TopicSubscriber.close方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSubscriber.close方法的具體用法?Java TopicSubscriber.close怎麽用?Java TopicSubscriber.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.TopicSubscriber的用法示例。


在下文中一共展示了TopicSubscriber.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWithSessionCloseOutsideTheLoop

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public void testWithSessionCloseOutsideTheLoop() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      for (int i = 0; i < 100; i++) {

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

   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:NetworkRemovesSubscriptionsTest.java

示例2: testGetTopic

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@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) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolTopicSubscriberTest.java

示例3: testGetNoLocal

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@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) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:17,代碼來源:JmsPoolTopicSubscriberTest.java

示例4: testDurableSubscriptionUnsubscribe

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribe() throws Exception {
   Connection connection = createConnection("myClientId");

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(getTopicName());
      TopicSubscriber myDurSub = session.createDurableSubscriber(topic, "myDurSub");
      session.close();
      connection.close();

      connection = createConnection("myClientId");
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      myDurSub = session.createDurableSubscriber(topic, "myDurSub");
      myDurSub.close();

      Assert.assertNotNull(server.getPostOffice().getBinding(new SimpleString("myClientId.myDurSub")));
      session.unsubscribe("myDurSub");
      Assert.assertNull(server.getPostOffice().getBinding(new SimpleString("myClientId.myDurSub")));
      session.close();
      connection.close();
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:JMSTopicConsumerTest.java

示例5: testWithSessionAndSubsciberClose

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
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());
   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:20,代碼來源:NetworkRemovesSubscriptionsTest.java

示例6: testWithoutSessionAndSubsciberClosePlayAround

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
/**
 * 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());
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:27,代碼來源:NetworkRemovesSubscriptionsTest.java

示例7: collectMessagesFromDurableSubscriptionForOneMinute

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:18,代碼來源:DurableSubscriptionHangTestCase.java

示例8: testRemove

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public void testRemove() 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();

   assertTrue(Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         return broker.getAdminView().getInactiveDurableTopicSubscribers().length == 0;
      }
   }, 15000));
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:17,代碼來源:DurableSubscriptionRemoveOfflineTest.java

示例9: testRemoveAfterRestart

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
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));
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:25,代碼來源:DurableSubscriptionRemoveOfflineTest.java

示例10: testGetNoLocalOnClosedConsumer

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@Test
public void testGetNoLocalOnClosedConsumer() throws Exception {
   Connection consumerConnection = null;

   try {
      consumerConnection = createConnection();
      TopicConnection tc = (TopicConnection) consumerConnection;

      TopicSession consumerSession = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      TopicSubscriber topicConsumer = consumerSession.createSubscriber(ActiveMQServerTestCase.topic1);

      topicConsumer.close();

      try {
         topicConsumer.getNoLocal();
         Assert.fail("must throw a JMS IllegalStateException");
      } catch (javax.jms.IllegalStateException e) {
         // OK
      }
   } finally {
      if (consumerConnection != null) {
         consumerConnection.close();
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:27,代碼來源:MessageConsumerTest.java

示例11: testUnsubscribeWithActiveConsumer

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@Test
public void testUnsubscribeWithActiveConsumer() throws Exception {
   Connection conn = createConnection();
   conn.setClientID("zeke");

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

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

   try {
      s.unsubscribe("dursub0");
      ProxyAssertSupport.fail();
   } catch (IllegalStateException e) {
      // Ok - it is illegal to ubscribe a subscription if it has active consumers
   }

   dursub.close();

   s.unsubscribe("dursub0");
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:DurableSubscriptionTest.java

示例12: testSubscribeWithActiveSubscription

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@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");
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:DurableSubscriptionTest.java

示例13: testClientDeleteQueueSuccess

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public void testClientDeleteQueueSuccess() throws Exception
{
    try
    {
        Connection conn = getConnection("test", "client", "guest");
        Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
        conn.start();

        // create kipper
        Topic kipper = sess.createTopic("kipper");
        TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");

        subscriber.close();
        sess.unsubscribe("kipper");

        //Do something to show connection is active.
        sess.rollback();
        conn.close();
    }
    catch (Exception e)
    {
        fail("Test failed due to:" + e.getMessage());
    }
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:25,代碼來源:ExternalACLTest.java

示例14: testServerDeleteQueueFailure

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public void testServerDeleteQueueFailure() throws Exception
{
    try
    {
        Connection conn = getConnection("test", "server", "guest");
        Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
        conn.start();

        // create kipper
        Topic kipper = sess.createTopic("kipper");
        TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");

        subscriber.close();
        sess.unsubscribe("kipper");

        //Do something to show connection is active.
        sess.rollback();
        conn.close();
    }
    catch (JMSException e)
    {
        // JMSException -> linedException = AMQException.403
        check403Exception(e.getLinkedException());
    }
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:26,代碼來源:ExternalACLTest.java

示例15: unsubscribe

import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@Override
public boolean unsubscribe(String channel) {
    TopicSubscriber subscriber = this.subscribers.remove(channel);
    
    if (subscriber == null) {
        return false;
    }
    
    log.debug(String.format("Unsubscribing Subscriber[%s] for Topic [%s].", subscriber, channel));
    
    try {
        subscriber.setMessageListener(null);
        subscriber.close();
    } catch (JMSException e) {}
    
    return true;
}
 
開發者ID:carewebframework,項目名稱:carewebframework-core,代碼行數:18,代碼來源:MessageConsumer.java


注:本文中的javax.jms.TopicSubscriber.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。