骆驼交换通过码头延续到期

Camel exchange expired via jetty continuation

是否有可能在 Apache Camel 中注册一个处理程序来管理由于已达到持续超时而无法写入码头端点 http 响应的交换?

不,这是不可能的。如果您有一些处理缓慢的交换,可能需要设置更高的超时时间。

欢迎您深入了解 Jetty API,看看是否可以找到此类 onTimeout 事件的挂钩,并了解在 camel-jetty 中支持该事件需要什么。

我只是添加我的注释,因为我通过修改 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