1

我正在尝试实现更高级的 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;
}

但是这段代码对我来说很臭,我不喜欢它,而且我在这里看不到任何方法来收集导致所有这些重试的异常。

4

2 回答 2

1

Camel 2.11 中还有一个新的控制总线组件,它可以做你想做的事(来源

template.sendBody("controlbus:route?routeId=foo&action=stop", null);
于 2012-12-09T17:56:27.107 回答
0

我不会尝试关闭 CamelContext,只是关闭有问题的路线......这样您的应用程序的其余部分仍然可以运行,您可以获得路线统计信息并查看/移动消息到备用队列等。

https://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

于 2012-12-07T17:21:18.613 回答