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


Java TopicSubscriber類代碼示例

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


TopicSubscriber類屬於javax.jms包,在下文中一共展示了TopicSubscriber類的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: JMSSink

import javax.jms.TopicSubscriber; //導入依賴的package包/類
public JMSSink(final String tcfBindingName, final String topicBindingName, final String username,
               final String password) {

   try {
      final Context ctx = new InitialContext();
      final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) lookup(ctx,
              tcfBindingName);

      final TopicConnection topicConnection =
              topicConnectionFactory.createTopicConnection(username,
                      password);
      topicConnection.start();

      final TopicSession topicSession = topicConnection.createTopicSession(false,
              Session.AUTO_ACKNOWLEDGE);

      final Topic topic = (Topic) ctx.lookup(topicBindingName);

      final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);

      topicSubscriber.setMessageListener(this);

   } catch (final Exception e) {
      logger.error("Could not read JMS message.", e);
   }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:27,代碼來源:JMSSink.java

示例5: closeConsumer

import javax.jms.TopicSubscriber; //導入依賴的package包/類
/**
 * Close a JMS {@link MessageConsumer}.
 * @param messageConsumer JMS Message Consumer that needs to be closed.
 * @throws JMSException if an error occurs while closing the consumer.
 */
public void closeConsumer(MessageConsumer messageConsumer) throws JMSException {
    if (messageConsumer != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Closing a JMS Message Consumer of: " + this.connectionFactoryString);
        }
        if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0
                .equals(jmsSpec))) {
            messageConsumer.close();
        } else {
            if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
                if (messageConsumer instanceof QueueReceiver) {
                    ((QueueReceiver) messageConsumer).close();
                }
            } else {
                if (messageConsumer instanceof  TopicSubscriber) {
                    ((TopicSubscriber) messageConsumer).close();
                }
            }
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:27,代碼來源:JMSConnectionResourceFactory.java

示例6: testNotificationProperties

import javax.jms.TopicSubscriber; //導入依賴的package包/類
@Test
public void testNotificationProperties() throws Exception {
   try (TopicConnection topicConnection = factory.createTopicConnection()) {
      TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic notificationsTopic = topicSession.createTopic("activemq.notifications");
      TopicSubscriber subscriber = topicSession.createSubscriber(notificationsTopic);
      List<Message> receivedMessages = new CopyOnWriteArrayList<>();
      subscriber.setMessageListener(receivedMessages::add);
      topicConnection.start();

      Wait.waitFor(() -> receivedMessages.size() > 0);

      Assert.assertTrue(receivedMessages.size() > 0);

      for (Message message : receivedMessages) {
         assertNotNull(message);
         assertNotNull(message.getStringProperty("_AMQ_NotifType"));
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:SimpleOpenWireTest.java

示例7: testSendAndReceiveOnTopic

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

   try {
      TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(getTopicName());
      TopicSubscriber consumer = session.createSubscriber(topic);
      TopicPublisher producer = session.createPublisher(topic);

      TextMessage message = session.createTextMessage("test-message");
      producer.send(message);

      producer.close();
      connection.start();

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

      assertNotNull(message);
      assertNotNull(message.getText());
      assertEquals("test-message", message.getText());
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:JMSTopicConsumerTest.java

示例8: 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

示例9: 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

示例10: testWithOneSubscriber

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

示例11: testWithoutSessionAndSubsciberClose

import javax.jms.TopicSubscriber; //導入依賴的package包/類
public void testWithoutSessionAndSubsciberClose() 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);
         assertNotNull(subscriber);
      }

      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());
   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:18,代碼來源:NetworkRemovesSubscriptionsTest.java

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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