本文整理匯總了Java中javax.jms.TopicSubscriber.setMessageListener方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSubscriber.setMessageListener方法的具體用法?Java TopicSubscriber.setMessageListener怎麽用?Java TopicSubscriber.setMessageListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicSubscriber
的用法示例。
在下文中一共展示了TopicSubscriber.setMessageListener方法的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: JMSSink
import javax.jms.TopicSubscriber; //導入方法依賴的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);
}
}
示例3: testNotificationProperties
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
@Test
public void testNotificationProperties() throws Exception {
try (TopicConnection topicConnection = factory.createTopicConnection()) {
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic notificationsTopic = topicSession.createTopic("activemq.notifications");
TopicSubscriber subscriber = topicSession.createSubscriber(notificationsTopic);
List<Message> receivedMessages = new CopyOnWriteArrayList<>();
subscriber.setMessageListener(receivedMessages::add);
topicConnection.start();
Wait.waitFor(() -> receivedMessages.size() > 0);
Assert.assertTrue(receivedMessages.size() > 0);
for (Message message : receivedMessages) {
assertNotNull(message);
assertNotNull(message.getStringProperty("_AMQ_NotifType"));
}
}
}
示例4: 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());
}
示例5: testWithOneSubscriber
import javax.jms.TopicSubscriber; //導入方法依賴的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());
}
示例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: initTopicSubscriber
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public synchronized void initTopicSubscriber() throws JMSException, NamingException {
//first of all we have to inititiate the TopicSession
//(without this we can't instantiate a TopicSubscriber)
initTopicSession();
//get the TopicSubscriber from our TopicSession
TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic, null, true);
logger.debug("Topic subscriber created");
//if set we pass our ExtendedMessageListener to the TopicSubscriber as MessageListener
if (messageListener != null) {
topicSubscriber.setMessageListener(messageListener);
}
//start listening to JMS
topicConnection.start();
logger.info("Topic connection started");
}
示例8: 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;
}
示例9: subscribe
import javax.jms.TopicSubscriber; //導入方法依賴的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);
}
示例10: createConnectionAndReceiveMessage
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public void createConnectionAndReceiveMessage(String clientId, String ipAddress) throws JMSException {
Connection connection = connectionFactory.createConnection();
connection.setClientID(clientId);
connection.start();
Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
String selector = "s_id = 'Sample'";
logger.info("selector : '" + selector + "'....");
TopicSubscriber consumer = session.createDurableSubscriber(topic, "Sub1", selector, true);
consumer.setMessageListener(topicMessageListener);
}
示例11: load
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
public synchronized void load() throws GenericServiceException {
try {
InitialContext jndi = JNDIContextFactory.getInitialContext(jndiServer);
TopicConnectionFactory factory = (TopicConnectionFactory) jndi.lookup(jndiName);
if (factory != null) {
con = factory.createTopicConnection(userName, password);
con.setExceptionListener(this);
session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic) jndi.lookup(topicName);
if (topic != null) {
TopicSubscriber subscriber = session.createSubscriber(topic);
subscriber.setMessageListener(this);
con.start();
this.setConnected(true);
if (Debug.infoOn()) Debug.logInfo("Listening to topic [" + topicName + "] on [" + jndiServer + "]...", module);
} else {
throw new GenericServiceException("Topic lookup failed.");
}
} else {
throw new GenericServiceException("Factory (broker) lookup failed.");
}
} catch (NamingException ne) {
throw new GenericServiceException("JNDI lookup problems; listener not running.", ne);
} catch (JMSException je) {
throw new GenericServiceException("JMS internal error; listener not running.", je);
} catch (GeneralException ge) {
throw new GenericServiceException("Problems with InitialContext; listener not running.", ge);
}
}
示例12: setUpConnection
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
private void setUpConnection() throws JMSException {
setConnection("clientid");
Topic topic = session.createTopic("upstream-odd-even");
// connection.setClientID("durable1");
TopicSubscriber subscriber = session.createDurableSubscriber(topic, "sub");// (topic);
// subscriber.
subscriber.setMessageListener(this);
connection.start();
}
示例13: setUpJMSConnection
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
private void setUpJMSConnection() throws JMSException {
this.setJMSConnection("clientid");
Topic topic = session.createTopic(CONFIG.get("UPSTREAM_TOPIC_NAME"));
TopicSubscriber subscriber =
session.createDurableSubscriber(topic, CONFIG.get("DURABLE_SUBSCRIBER_NAME"));// (topic);
subscriber.setMessageListener(this);
LOGGER.info("About to connect..");
connection.start();
LOGGER.info("Consumption should begin now..");
}
示例14: setUpConnection
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
private void setUpConnection() throws JMSException {
this.setConnection("clientid");
Topic topic = session.createTopic(CONFIG.get("UPSTREAM_TOPIC_NAME"));
TopicSubscriber subscriber =
session.createDurableSubscriber(topic, CONFIG.get("DURABLE_SUBSCRIBER_NAME"));// (topic);
subscriber.setMessageListener(this);
LOGGER.info("About to connect..");
connection.start();
LOGGER.info("Consumption should begin now..");
}
示例15: registerDurableConsumer
import javax.jms.TopicSubscriber; //導入方法依賴的package包/類
private ActiveMQTopic registerDurableConsumer(BrokerService brokerService,
MessageListener listener) throws Exception {
ConnectionFactory factory = createConnectionFactory(brokerService);
Connection connection = factory.createConnection();
connection.setClientID("DurableOne");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQTopic destination = (ActiveMQTopic) session.createTopic(DESTINATION_NAME);
// unique to a broker
TopicSubscriber sub = session.createDurableSubscriber(destination, "SubOne" + brokerService.getBrokerName());
sub.setMessageListener(listener);
return destination;
}