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


Java TopicConnection.start方法代碼示例

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


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

示例1: testWithSessionCloseOutsideTheLoop

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

import javax.jms.TopicConnection; //導入方法依賴的package包/類
/**
 * @param topicConnection
 * @param chatTopic
 * @param userId
 * @throws JMSException
 * @throws IOException
 */
void publish(TopicConnection topicConnection, Topic chatTopic, String userId)
		throws JMSException, IOException {
	TopicSession tsession = topicConnection.createTopicSession(false,
			Session.AUTO_ACKNOWLEDGE);
	TopicPublisher topicPublisher = tsession.createPublisher(chatTopic);
	topicConnection.start();
	
	BufferedReader reader = new BufferedReader(new InputStreamReader(
			System.in));
	while (true) {
		String msgToSend = reader.readLine();
		if (msgToSend.equalsIgnoreCase("exit")) {
			topicConnection.close();
			System.exit(0);
		} else {

			TextMessage msg = (TextMessage) tsession.createTextMessage();
			msg.setText("\n["+userId + " : " + msgToSend+"]");
			topicPublisher.publish(msg);
		}
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:30,代碼來源:BasicJMSChat.java

示例3: testWithTopicConnection

import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test
public void testWithTopicConnection() throws JMSException {
	Connection con = mock(TopicConnection.class);

	SingleConnectionFactory scf = new SingleConnectionFactory(con);
	TopicConnection con1 = scf.createTopicConnection();
	con1.start();
	con1.stop();
	con1.close();
	TopicConnection con2 = scf.createTopicConnection();
	con2.start();
	con2.stop();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(con, times(2)).start();
	verify(con, times(2)).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:SingleConnectionFactoryTests.java

示例4: JMSSink

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

import javax.jms.TopicConnection; //導入方法依賴的package包/類
/**
 * To publish the messages to a topic.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void publishMessagesToTopic(String topicName) throws JMSException, InterruptedException {
    TopicConnection topicConnection = (TopicConnection) connectionFactory.createConnection();
    topicConnection.start();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = topicSession.createTopic(topicName);
    MessageProducer topicSender = topicSession.createProducer(destination);
    topicSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    for (int index = 0; index < 10; index++) {
        String topicText = "Topic Message : " + (index + 1);
        TextMessage topicMessage = topicSession.createTextMessage(topicText);
        topicSender.send(topicMessage);
        logger.info("Publishing " + topicText + " to topic " + topicName);
        Thread.sleep(1000);
    }
    topicConnection.close();
    topicSession.close();
    topicSender.close();
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:25,代碼來源:JMSServer.java

示例6: testWithSessionAndSubsciberClose

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

示例7: testWithOneSubscriber

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

示例8: testWithoutSessionAndSubsciberClose

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

示例9: testWithoutSessionAndSubsciberClosePlayAround

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

示例10: collectMessagesFromDurableSubscriptionForOneMinute

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

示例11: testPersistentMessagesForTopicDropped2

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

示例12: testWithTopicConnection

import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test
public void testWithTopicConnection() throws JMSException {
	Connection con = mock(TopicConnection.class);

	SingleConnectionFactory scf = new SingleConnectionFactory(con);
	TopicConnection con1 = scf.createTopicConnection();
	con1.start();
	con1.stop();  // should be ignored
	con1.close();  // should be ignored
	TopicConnection con2 = scf.createTopicConnection();
	con2.start();
	con2.stop();  // should be ignored
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:21,代碼來源:SingleConnectionFactoryTests.java

示例13: testConnectionFactory102WithTopic

import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test
public void testConnectionFactory102WithTopic() throws JMSException {
	TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
	TopicConnection con = mock(TopicConnection.class);

	given(cf.createTopicConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory102(cf, true);
	TopicConnection con1 = scf.createTopicConnection();
	con1.start();
	con1.close();  // should be ignored
	TopicConnection con2 = scf.createTopicConnection();
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:SingleConnectionFactoryTests.java

示例14: createTopic

import javax.jms.TopicConnection; //導入方法依賴的package包/類
public static Topic createTopic(String uri, String topicName) throws JMSException {
	TopicConnectionFactory connectionFactory = null;
	TopicConnection connection = null;
	TopicSession session = null;
	Topic topic = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createTopicConnection();
		connection.start();
		session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		topic = session.createTopic(topicName);
		session.commit();
	} finally {
		closeQuietly(session);
		closeQuietly(connection);
	}
	return topic;
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:19,代碼來源:MsgUtils.java

示例15: publishTextMsg2Topic

import javax.jms.TopicConnection; //導入方法依賴的package包/類
/**
 * Product message for assigned topic.
 * 
 * @param uri
 *            e.g.: tcp://3CNL12096:61616
 * @param queueName
 *            name of queue
 * @throws JMSException
 */
public static void publishTextMsg2Topic(String uri, String topicName, String text) throws JMSException {
	TopicConnectionFactory connectionFactory = null;
	TopicConnection connection = null;
	TopicSession session = null;
	TopicPublisher tp = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createTopicConnection();
		connection.start();
		session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		tp = session.createPublisher(session.createTopic(topicName));
		tp.setDeliveryMode(DeliveryMode.PERSISTENT);
		tp.publish(session.createTextMessage(text));
		session.commit();
	} finally {
		closeQuietly(tp);
		closeQuietly(session);
		closeQuietly(connection);
	}
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:30,代碼來源:MsgUtils.java


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