* Creates a {@link PollingConsumer} and polls all pending messages on the endpoint
* and invokes the given {@link Processor} to process each {@link Exchange} and then closes
* down the consumer and throws any exceptions thrown.
*/
public static void pollEndpoint(Endpoint endpoint, Processor processor, long timeout) throws Exception {
PollingConsumer consumer = endpoint.createPollingConsumer();
try {
consumer.start();
while (true) {
Exchange exchange = consumer.receive(timeout);
if (exchange == null) {
break;
} else {
processor.process(exchange);
}
}
} finally {
try {
consumer.stop();
} catch (Exception e) {
LOG.warn("Failed to stop PollingConsumer: " + e, e);
}
}
}