本文整理匯總了Java中javax.jms.MessageConsumer.receiveNoWait方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageConsumer.receiveNoWait方法的具體用法?Java MessageConsumer.receiveNoWait怎麽用?Java MessageConsumer.receiveNoWait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.MessageConsumer
的用法示例。
在下文中一共展示了MessageConsumer.receiveNoWait方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testReceiveNoWait
import javax.jms.MessageConsumer; //導入方法依賴的package包/類
@Test
public void testReceiveNoWait() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
Session session = connection.createSession();
Queue queue = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(queue, "Color = Red");
assertNull(consumer.receiveNoWait());
consumer.close();
try {
consumer.receiveNoWait();
fail("Should not be able to interact with closed consumer");
} catch (IllegalStateException ise) {}
}
示例2: doCleanupQueue
import javax.jms.MessageConsumer; //導入方法依賴的package包/類
private void doCleanupQueue( final Session session, final Destination destination ) throws JMSException {
try {
MessageConsumer consumer = session.createConsumer(destination);
Message message = null;
do {
message = consumer.receiveNoWait();
if (message != null) {
message.acknowledge();
}
} while (message != null);
} finally {
releaseSession(false);
}
}