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


Java TopicSession.createSubscriber方法代碼示例

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


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

示例1: testWithSessionCloseOutsideTheLoop

import javax.jms.TopicSession; //導入方法依賴的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.TopicSession; //導入方法依賴的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: JMSSink

import javax.jms.TopicSession; //導入方法依賴的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

示例4: testSendAndReceiveOnTopic

import javax.jms.TopicSession; //導入方法依賴的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

示例5: testWithSessionAndSubsciberClose

import javax.jms.TopicSession; //導入方法依賴的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: testWithOneSubscriber

import javax.jms.TopicSession; //導入方法依賴的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

示例7: testWithoutSessionAndSubsciberClose

import javax.jms.TopicSession; //導入方法依賴的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

示例8: testWithoutSessionAndSubsciberClosePlayAround

import javax.jms.TopicSession; //導入方法依賴的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

示例9: testGetNoLocalOnClosedConsumer

import javax.jms.TopicSession; //導入方法依賴的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

示例10: testPersistentMessagesForTopicDropped2

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Topics shouldn't hold on to messages when the non-durable subscribers close
 */
@Test
public void testPersistentMessagesForTopicDropped2() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   topicConn.start();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   TopicSubscriber sub = sess.createSubscriber(ActiveMQServerTestCase.topic1);
   pub.setDeliveryMode(DeliveryMode.PERSISTENT);

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   // receive but rollback
   TextMessage m2 = (TextMessage) sub.receive(3000);

   ProxyAssertSupport.assertNotNull(m2);
   ProxyAssertSupport.assertEquals("testing123", m2.getText());

   sess.rollback();

   topicConn.close();

   checkEmpty(ActiveMQServerTestCase.topic1);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:29,代碼來源:AcknowledgementTest.java

示例11: createSubscriber

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Create a topic subscriber
 *
 * @param topic The topic
 * @return The subscriber
 * @throws JMSException Thrown if an error occurs
 */
@Override
public TopicSubscriber createSubscriber(final Topic topic) throws JMSException {
   lock();
   try {
      TopicSession session = getTopicSessionInternal();

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createSubscriber " + session + " topic=" + topic);
      }

      TopicSubscriber result = session.createSubscriber(topic);
      result = new ActiveMQRATopicSubscriber(result, this);

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createdSubscriber " + session + " ActiveMQTopicSubscriber=" + result);
      }

      addConsumer(result);

      return result;
   } finally {
      unlock();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:32,代碼來源:ActiveMQRASession.java

示例12: testQueueReceiversAndTopicSubscriber

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testQueueReceiversAndTopicSubscriber() throws Exception
{
    Queue queue = new AMQAnyDestination("ADDR:my-queue; {create: always}");
    Topic topic = new AMQAnyDestination("ADDR:amq.topic/test");
    
    QueueSession qSession = ((AMQConnection)_connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueReceiver receiver = qSession.createReceiver(queue);
    
    TopicSession tSession = ((AMQConnection)_connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = tSession.createSubscriber(topic);
    
    Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer prod1 = ssn.createProducer(ssn.createQueue("ADDR:my-queue"));
    prod1.send(ssn.createTextMessage("test1"));
    
    MessageProducer prod2 = ssn.createProducer(ssn.createTopic("ADDR:amq.topic/test"));
    prod2.send(ssn.createTextMessage("test2"));
    
    Message msg1 = receiver.receive();
    assertNotNull(msg1);
    assertEquals("test1",((TextMessage)msg1).getText());
    
    Message msg2 = sub.receive();
    assertNotNull(msg2);
    assertEquals("test2",((TextMessage)msg2).getText());  
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:27,代碼來源:AddressBasedDestinationTest.java

示例13: createSubscriber

import javax.jms.TopicSession; //導入方法依賴的package包/類
public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
    lock();
    try {
        TopicSession session = getTopicSession();
        if (trace)
            log.trace("createSubscriber " + session + " topic=" + topic);
        TopicSubscriber result = session.createSubscriber(topic);
        result = new JmsTopicSubscriber(result, this);
        if (trace)
            log.trace("createdSubscriber " + session + " JmsTopicSubscriber=" + result);
        addConsumer(result);
        return result;
    } finally {
        unlock();
    }
}
 
開發者ID:vratsel,項目名稱:generic-jms-ra,代碼行數:17,代碼來源:JmsSession.java

示例14: testToString

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

示例15: subscribe

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * @param topicConnection
 * @param chatTopic
 * @param commandLineChat
 * @throws JMSException
 */
void subscribe(TopicConnection topicConnection, Topic chatTopic,
		BasicJMSChat commandLineChat) throws JMSException {
	TopicSession tsession = topicConnection.createTopicSession(false,
			Session.AUTO_ACKNOWLEDGE);
	TopicSubscriber ts = tsession.createSubscriber(chatTopic);
	ts.setMessageListener(commandLineChat);
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:14,代碼來源:BasicJMSChat.java


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