我正在尝试实现更高级的 Apache Camel 错误处理:如果有太多挂起的重试,则停止处理并在某处记录所有收集的异常。
第一部分(在太多重试时停止)已经通过以下辅助方法实现,它获取重试队列的大小,如果队列超过某个限制,我只是停止上下文:
static Long getToRetryTaskCount(CamelContext context) {
Long retryTaskCount = null;
ScheduledExecutorService errorHandlerExecutor = context.getErrorHandlerExecutorService();
if (errorHandlerExecutor instanceof SizedScheduledExecutorService)
{
SizedScheduledExecutorService svc = (SizedScheduledExecutorService) errorHandlerExecutor;
ScheduledThreadPoolExecutor executor = svc.getScheduledThreadPoolExecutor();
BlockingQueue<Runnable> queue = executor.getQueue();
retryTaskCount = (long) queue.size();
}
return retryTaskCount;
}
但是这段代码对我来说很臭,我不喜欢它,而且我在这里看不到任何方法来收集导致所有这些重试的异常。