本文整理匯總了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());
}
示例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) {}
}
示例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) {}
}
示例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();
}
}
示例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());
}
示例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());
}
示例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;
}
示例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));
}
示例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));
}
示例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();
}
}
}
示例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");
}
示例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");
}
示例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());
}
}
示例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());
}
}
示例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;
}