【发布时间】:2016-04-15 20:36:30
【问题描述】:
是否有可能在 Apache Camel 中注册一个处理程序来管理由于已达到持续超时而无法写入码头端点 http 响应的交换?
【问题讨论】:
标签: jetty apache-camel
是否有可能在 Apache Camel 中注册一个处理程序来管理由于已达到持续超时而无法写入码头端点 http 响应的交换?
【问题讨论】:
标签: jetty apache-camel
我将添加我的注释,因为我通过像这样修改 if (continuation.isExpired()) 块中的 CamelContinuationServlet 使其在我的项目中可用
if (continuation.isExpired()) {
String id = (String) continuation.getAttribute(EXCHANGE_ATTRIBUTE_ID);
// remember this id as expired
expiredExchanges.put(id, id);
log.warn("Continuation expired of exchangeId: {}", id);
consumer.getBinding().doWriteExceptionResponse(new TimeoutException(), response);
return;
}
在我的代码中结合一个名为 ErrorHandlingHttpBinding 的自定义 HttpBinding
public class ErrorHandlingHttpBinding extends DefaultHttpBinding {
@Override
public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
if (exception instanceof TimeoutException) {
response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
response.getWriter().write("Continuation timed out...");
} else {
super.doWriteExceptionResponse(exception, response);
}
}
}
使用id="errorHandlingHttpBinding" 注册为spring bean,并在组件字符串中引用为jetty:http://localhost:21010/?useContinuation=true&continuationTimeout=1&httpBindingRef=errorHandlingHttpBinding。
【讨论】:
不,这是不可能的。如果您有一些缓慢的处理交换,也许您需要设置更高的超时时间。
欢迎您深入了解 Jetty API,看看是否可以找到此类 onTimeout 事件的挂钩,并了解在 camel-jetty 中支持该事件需要什么。
【讨论】: