我正在设计一个使用Mulesoft的api,我想让它在响应时间超过10秒时返回一个通用响应。目前,我正在通过使用HTTP连接器调用api中的另一个流来实现这一点。
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8081" responseTimeout="10000" doc:name="HTTP Request Configuration"/>
<flow name="Incomming-Flow">
<!-- get request -->
<http:request config-ref="HTTP_Request_Configuration" path="/validationWithTimeout" method="POST" doc:name="HTTP"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<!-- Set payload to generic response when http call times out -->
</catch-exception-strategy>
</flow>
<flow name="Processing-Flow">
<http:listener config-ref="HTTP_Request_Configuration" path="/validationWithTimeout" allowedMethods="POST" doc:name="HTTP"/>
<!--
processing components go here
-->
</flow>有没有一种更好的方法来停止流,并在花费太长时间时返回通用响应?
发布于 2017-03-23 04:51:56
检查以上配置后,唯一的缺失点是超时变量及其使用,请为响应定义10秒的超时,当超时时需要抛出异常。
发布于 2016-11-15 10:16:54
单向-在异常处理本身内捕获,并在set payload set中设置需要的状态,无论通用响应需要什么。示例如下,您也可以使用Mapping-exception Strategy根据状态码进行捕获。
<flow name="Incomming-Flow">
<!-- get request -->
<http:request config-ref="HTTP_Request_Configuration" path="/validationWithTimeout" method="POST" doc:name="HTTP"/>
<catch-exception-strategy doc:name="Catch Exception Strategy" when="java.net.ConnectException">
<set-property propertyName="http.status" value="#[403]" doc:name="Property"/>
<set-payload value="{"success":false,"errors":[{"code":"50001","message":"Internal Server Error","details":"An internal system error has occurred, please contact the support team."}]}" doc:name="Set Payload" mimeType="application/json"/>
</catch-exception-strategy>
</flow>发布于 2017-02-18 01:17:29
您可以在全局设置配置中配置defaultResponseTimeout。将以下内容放入您的<mule>元素中。<configuration defaultResponseTimeout="10000"></configuration>,但请注意,这将适用于所有流。然后,可以在异常处理程序中配置异常。
https://stackoverflow.com/questions/40596235
复制相似问题