本文整理匯總了Java中javax.jms.TopicConnection.close方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicConnection.close方法的具體用法?Java TopicConnection.close怎麽用?Java TopicConnection.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicConnection
的用法示例。
在下文中一共展示了TopicConnection.close方法的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());
}
示例2: testSenderAndPublisherDest
import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
"vm://test?broker.persistent=false&broker.useJmx=false"));
QueueConnection connection = pcf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(session.createQueue("AA"));
assertNotNull(sender.getQueue().getQueueName());
connection.close();
TopicConnection topicConnection = pcf.createTopicConnection();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
assertNotNull(topicPublisher.getTopic().getTopicName());
topicConnection.close();
pcf.stop();
}
示例3: 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);
}
}
}
示例4: 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);
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例11: testPersistentMessagesForTopicDropped
import javax.jms.TopicConnection; //導入方法依賴的package包/類
/**
* Topics shouldn't hold on to messages if there are no subscribers
*/
@Test
public void testPersistentMessagesForTopicDropped() throws Exception {
TopicConnection topicConn = createTopicConnection();
TopicSession sess = topicConn.createTopicSession(true, 0);
TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
pub.publish(m);
sess.commit();
topicConn.close();
checkEmpty(ActiveMQServerTestCase.topic1);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: testTopicCreateConnectionGoodProviderString
import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test(timeout=20000)
public void testTopicCreateConnectionGoodProviderString() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
// Ignore errors from peer close due to not sending any Open / Close frames
testPeer.setSuppressReadExceptionOnClose(true);
// DONT create a test fixture, we will drive everything directly.
testPeer.expectSaslAnonymous();
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:" + testPeer.getServerPort());
TopicConnection connection = factory.createTopicConnection();
assertNotNull(connection);
testPeer.waitForAllHandlersToComplete(1000);
testPeer.expectOpen();
testPeer.expectClose();
connection.close();
testPeer.waitForAllHandlersToCompleteNoAssert(1000);
}
}