本文整理匯總了Java中javax.jms.TopicSession.close方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSession.close方法的具體用法?Java TopicSession.close怎麽用?Java TopicSession.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicSession
的用法示例。
在下文中一共展示了TopicSession.close方法的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());
}
示例2: initializeInboundDestinationBridgesOutboundSide
import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException {
if (inboundTopicBridges != null) {
TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
for (InboundTopicBridge bridge : inboundTopicBridges) {
String TopicName = bridge.getInboundTopicName();
Topic foreignTopic = createForeignTopic(outboundSession, TopicName);
bridge.setConsumer(null);
bridge.setConsumerTopic(foreignTopic);
bridge.setConsumerConnection(connection);
bridge.setJmsConnector(this);
addInboundBridge(bridge);
}
outboundSession.close();
}
}
示例3: initializeInboundDestinationBridgesLocalSide
import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException {
if (inboundTopicBridges != null) {
TopicSession localSession = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
for (InboundTopicBridge bridge : inboundTopicBridges) {
String localTopicName = bridge.getLocalTopicName();
Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
bridge.setProducerTopic(activemqTopic);
bridge.setProducerConnection(connection);
if (bridge.getJmsMessageConvertor() == null) {
bridge.setJmsMessageConvertor(getInboundMessageConvertor());
}
bridge.setJmsConnector(this);
addInboundBridge(bridge);
}
localSession.close();
}
}
示例4: initializeOutboundDestinationBridgesOutboundSide
import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException {
if (outboundTopicBridges != null) {
TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
for (OutboundTopicBridge bridge : outboundTopicBridges) {
String topicName = bridge.getOutboundTopicName();
Topic foreignTopic = createForeignTopic(outboundSession, topicName);
bridge.setProducerTopic(foreignTopic);
bridge.setProducerConnection(connection);
if (bridge.getJmsMessageConvertor() == null) {
bridge.setJmsMessageConvertor(getOutboundMessageConvertor());
}
bridge.setJmsConnector(this);
addOutboundBridge(bridge);
}
outboundSession.close();
}
}
示例5: initializeOutboundDestinationBridgesLocalSide
import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException {
if (outboundTopicBridges != null) {
TopicSession localSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
for (OutboundTopicBridge bridge : outboundTopicBridges) {
String localTopicName = bridge.getLocalTopicName();
Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
bridge.setConsumer(null);
bridge.setConsumerTopic(activemqTopic);
bridge.setConsumerConnection(connection);
bridge.setJmsConnector(this);
addOutboundBridge(bridge);
}
localSession.close();
}
}
示例6: publishMessagesToTopic
import javax.jms.TopicSession; //導入方法依賴的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();
}
示例7: 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());
}
示例8: 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());
}
示例9: 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());
}
示例10: testSubscriberPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({ "broker-port"})
@Test
public void testSubscriberPublisher(String port) throws Exception {
String topicName = "MyTopic1";
int numberOfMessages = 100;
InitialContext initialContext = ClientHelper
.getInitialContextBuilder("admin", "admin", "localhost", port)
.withTopic(topicName)
.build();
TopicConnectionFactory connectionFactory
= (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
// Initialize subscriber
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic subscriberDestination = (Topic) initialContext.lookup(topicName);
TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination);
// publish 100 messages
TopicSession producerSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher producer = producerSession.createPublisher(subscriberDestination);
for (int i = 0; i < numberOfMessages; i++) {
producer.publish(producerSession.createTextMessage("Test message " + i));
}
producerSession.close();
for (int i = 0; i < numberOfMessages; i++) {
Message message = subscriber.receive(1000);
Assert.assertNotNull(message, "Message #" + i + " was not received");
}
connection.close();
}
示例11: closeResources
import javax.jms.TopicSession; //導入方法依賴的package包/類
private static void closeResources(TopicConnection pConn, TopicSession pSession,
TopicPublisher pPublisher) throws JMSException {
if (pPublisher != null) {
pPublisher.close();
}
if (pSession != null) {
pSession.close();
}
if (pConn != null) {
pConn.close();
}
}
示例12: testTemporarySubscriptionDeleted
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
Connection connection = createConnection();
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber myNonDurSub = session.createSubscriber(topic);
assertNotNull(myNonDurSub);
Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(2, bindingsForAddress.getBindings().size());
session.close();
final CountDownLatch latch = new CountDownLatch(1);
server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
connection.close();
latch.await(5, TimeUnit.SECONDS);
bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(1, bindingsForAddress.getBindings().size());
} finally {
connection.close();
}
}
示例13: close
import javax.jms.TopicSession; //導入方法依賴的package包/類
private void close(TopicSession session) {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
LOG.error("Couldn't close TopicSession", e);
}
}
}
示例14: testPositiveJMSSelectorConsumerProducer
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testPositiveJMSSelectorConsumerProducer(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws NamingException, JMSException {
String queueName = "testPositiveJMSSelectorConsumerProducer";
InitialContext initialContext = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withTopic(queueName)
.build();
TopicConnectionFactory connectionFactory
= (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) initialContext.lookup(queueName);
// Subscribe with a selector
String propertyName = "MyProperty";
String propertyValue = "propertyValue";
String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);
// publish messages with property
TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
TopicPublisher producer = producerSession.createPublisher(topic);
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
textMessage.setStringProperty(propertyName, propertyValue);
producer.send(textMessage);
}
// consume messages
for (int i = 0; i < numberOfMessages; i++) {
Message message = consumer.receive(1000);
Assert.assertNotNull(message, "Message #" + i + " was not received");
}
producerSession.close();
connection.close();
}
示例15: testNegativeJMSSelectorConsumerProducer
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testNegativeJMSSelectorConsumerProducer(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws NamingException, JMSException {
String queueName = "testNegativeJMSSelectorConsumerProducer";
InitialContext initialContext = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withTopic(queueName)
.build();
TopicConnectionFactory connectionFactory
= (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) initialContext.lookup(queueName);
// Subscribe with a selector
String propertyName = "MyProperty";
String propertyValue = "propertyValue";
String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);
// publish messages with property
TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
TopicPublisher producer = producerSession.createPublisher(topic);
// Send messages with a different property value
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
textMessage.setStringProperty(propertyName, propertyValue + "-1");
producer.send(textMessage);
}
// consume messages
Message message = consumer.receive(100);
Assert.assertNull(message, "Message received. Shouldn't receive any messages.");
producerSession.close();
connection.close();
}