use of javax.jms.QueueBrowser in project javaee7-samples by javaee-samples.
the class MessageReceiverSync method receiveAll.
public void receiveAll() {
System.out.println("--> Receiving redundant messages ...");
try {
QueueBrowser browser = context.createBrowser(myQueue);
while (browser.getEnumeration().hasMoreElements()) {
System.out.println("--> here is one");
context.createConsumer(myQueue).receiveBody(String.class, 1000);
}
} catch (JMSException ex) {
Logger.getLogger(MessageReceiverSync.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of javax.jms.QueueBrowser in project tomee by apache.
the class JMSContextImpl method createBrowser.
@Override
public QueueBrowser createBrowser(final Queue queue, final String messageSelector) {
try {
final QueueBrowser browser = session().createBrowser(queue, messageSelector);
checkAutoStart();
return browser;
} catch (final JMSException e) {
throw toRuntimeException(e);
}
}
use of javax.jms.QueueBrowser in project tomee by apache.
the class JMSContextImpl method createBrowser.
@Override
public QueueBrowser createBrowser(final Queue queue) {
try {
final QueueBrowser browser = session().createBrowser(queue);
checkAutoStart();
return browser;
} catch (final JMSException e) {
throw toRuntimeException(e);
}
}
use of javax.jms.QueueBrowser in project sling by apache.
the class JMSQueueManagerTest method emptyQueue.
private void emptyQueue(String name) throws JMSException {
dumpQueue(name);
Connection connection = amqConnectionFactoryService.getConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue(name);
MessageConsumer consumer = session.createConsumer(queue);
for (; ; ) {
Message m = consumer.receive(100);
if (m == null) {
LOGGER.info("No more messages in queue {} ", name);
break;
}
LOGGER.info("Got message {}", m);
m.acknowledge();
session.commit();
}
boolean shouldFail = false;
QueueBrowser browser = session.createBrowser(queue);
for (Enumeration messages = browser.getEnumeration(); messages.hasMoreElements(); ) {
Message m = (Message) messages.nextElement();
LOGGER.info("Queued message {} ", m);
shouldFail = true;
}
browser.close();
if (shouldFail) {
fail("Queue was not emptied as expected");
}
consumer.close();
session.close();
connection.stop();
}
use of javax.jms.QueueBrowser in project sling by apache.
the class JMSQueueManagerTest method checkMessagesInQueue.
private void checkMessagesInQueue(String name, int expected) throws JMSException {
Connection connection = amqConnectionFactoryService.getConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(name);
QueueBrowser browser = session.createBrowser(queue);
int n = 0;
for (Enumeration e = browser.getEnumeration(); e.hasMoreElements(); ) {
Message m = (Message) e.nextElement();
LOGGER.info("Message at {} is {} ", n, m);
n++;
}
browser.close();
session.close();
connection.stop();
assertEquals(expected, n);
}
Aggregations