本文整理匯總了Java中javax.jms.TopicConnection.createTopicSession方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicConnection.createTopicSession方法的具體用法?Java TopicConnection.createTopicSession怎麽用?Java TopicConnection.createTopicSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicConnection
的用法示例。
在下文中一共展示了TopicConnection.createTopicSession方法的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: 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);
}
}
示例5: initializeInboundDestinationBridgesOutboundSide
import javax.jms.TopicConnection; //導入方法依賴的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();
}
}
示例6: initializeInboundDestinationBridgesLocalSide
import javax.jms.TopicConnection; //導入方法依賴的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();
}
}
示例7: initializeOutboundDestinationBridgesOutboundSide
import javax.jms.TopicConnection; //導入方法依賴的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();
}
}
示例8: initializeOutboundDestinationBridgesLocalSide
import javax.jms.TopicConnection; //導入方法依賴的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();
}
}
示例9: 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();
}
示例10: 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);
}
示例11: 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());
}
示例12: 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());
}
示例13: testGetNoLocalOnClosedConsumer
import javax.jms.TopicConnection; //導入方法依賴的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();
}
}
}
示例14: 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;
}
示例15: 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);
}