【问题标题】:Camel exchange expired via jetty continuation骆驼交换通过码头延续到期
【发布时间】:2016-04-15 20:36:30
【问题描述】:

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

【问题讨论】:

    标签: jetty apache-camel


    【解决方案1】:

    我将添加我的注释,因为我通过像这样修改 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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 目前,有一个解决方案,但需要一些调整。您可以在下面查看我的建议并评估是否有可能在骆驼码头获得它。
      • 谢谢,这似乎是一个很好的解决方案。我已经为此记录了一张票:issues.apache.org/jira/browse/CAMEL-10175。欢迎您开发补丁/ PR 来实现这一点。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      相关资源
      最近更新 更多