本文整理匯總了Java中javax.jms.TopicSession.createSubscriber方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSession.createSubscriber方法的具體用法?Java TopicSession.createSubscriber怎麽用?Java TopicSession.createSubscriber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicSession
的用法示例。
在下文中一共展示了TopicSession.createSubscriber方法的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: testGetTopic
import javax.jms.TopicSession; //導入方法依賴的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: JMSSink
import javax.jms.TopicSession; //導入方法依賴的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);
}
}
示例4: testSendAndReceiveOnTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSendAndReceiveOnTopic() throws Exception {
Connection connection = createConnection("myClientId");
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber consumer = session.createSubscriber(topic);
TopicPublisher producer = session.createPublisher(topic);
TextMessage message = session.createTextMessage("test-message");
producer.send(message);
producer.close();
connection.start();
message = (TextMessage) consumer.receive(1000);
assertNotNull(message);
assertNotNull(message.getText());
assertEquals("test-message", message.getText());
} finally {
connection.close();
}
}
示例5: 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());
}
示例6: 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());
}
示例7: testWithoutSessionAndSubsciberClose
import javax.jms.TopicSession; //導入方法依賴的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());
}
示例8: 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());
}
示例9: testGetNoLocalOnClosedConsumer
import javax.jms.TopicSession; //導入方法依賴的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();
}
}
}
示例10: testPersistentMessagesForTopicDropped2
import javax.jms.TopicSession; //導入方法依賴的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);
}
示例11: createSubscriber
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Create a topic subscriber
*
* @param topic The topic
* @return The subscriber
* @throws JMSException Thrown if an error occurs
*/
@Override
public TopicSubscriber createSubscriber(final Topic topic) throws JMSException {
lock();
try {
TopicSession session = getTopicSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createSubscriber " + session + " topic=" + topic);
}
TopicSubscriber result = session.createSubscriber(topic);
result = new ActiveMQRATopicSubscriber(result, this);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdSubscriber " + session + " ActiveMQTopicSubscriber=" + result);
}
addConsumer(result);
return result;
} finally {
unlock();
}
}
示例12: testQueueReceiversAndTopicSubscriber
import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testQueueReceiversAndTopicSubscriber() throws Exception
{
Queue queue = new AMQAnyDestination("ADDR:my-queue; {create: always}");
Topic topic = new AMQAnyDestination("ADDR:amq.topic/test");
QueueSession qSession = ((AMQConnection)_connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = qSession.createReceiver(queue);
TopicSession tSession = ((AMQConnection)_connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber sub = tSession.createSubscriber(topic);
Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod1 = ssn.createProducer(ssn.createQueue("ADDR:my-queue"));
prod1.send(ssn.createTextMessage("test1"));
MessageProducer prod2 = ssn.createProducer(ssn.createTopic("ADDR:amq.topic/test"));
prod2.send(ssn.createTextMessage("test2"));
Message msg1 = receiver.receive();
assertNotNull(msg1);
assertEquals("test1",((TextMessage)msg1).getText());
Message msg2 = sub.receive();
assertNotNull(msg2);
assertEquals("test2",((TextMessage)msg2).getText());
}
示例13: createSubscriber
import javax.jms.TopicSession; //導入方法依賴的package包/類
public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
lock();
try {
TopicSession session = getTopicSession();
if (trace)
log.trace("createSubscriber " + session + " topic=" + topic);
TopicSubscriber result = session.createSubscriber(topic);
result = new JmsTopicSubscriber(result, this);
if (trace)
log.trace("createdSubscriber " + session + " JmsTopicSubscriber=" + result);
addConsumer(result);
return result;
} finally {
unlock();
}
}
示例14: testToString
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testToString() 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.toString());
}
示例15: subscribe
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* @param topicConnection
* @param chatTopic
* @param commandLineChat
* @throws JMSException
*/
void subscribe(TopicConnection topicConnection, Topic chatTopic,
BasicJMSChat commandLineChat) throws JMSException {
TopicSession tsession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
TopicSubscriber ts = tsession.createSubscriber(chatTopic);
ts.setMessageListener(commandLineChat);
}