全局异常处理程序 - mule
global exception handler - mule
我们有一个要求,我们想要编写一个全局异常处理程序,以便这个全局异常处理程序捕获任何单个流(我们有 80 多个 mule 流)上的任何异常。
基本上我们想添加一个全局配置并关联一个默认的全局捕获异常策略,以便在这里处理任何流程中的任何异常。
每个流程添加每个 'catch exception strategy' 是可行的,但我必须重复类似的代码 50 多次,出于明显的原因我想避免。
此外,请注意我想将特定参数传递给此全局异常策略,以便此全局异常策略也提供流特定信息。请建议。
注意:我在 mule 'Global Elements' 中没有看到全局捕获异常策略选项 UI。
参考文献:
Mule 特定文档没有明确说明。
https://docs.mulesoft.com/mule-user-guide/v/3.7/error-handling
这个需求看起来很像,但是传参等不是很清楚:
How to add a global exception handler/logger once in Mule
star的建议不错。此外,如果您想将参数传递给全局异常处理程序,一个好的方法是设置一个全局异常读取的流变量,并且永远不要忘记在您拥有的每个流上将一个值放入该变量。
您应该可以在 UI 中看到它。不知道为什么你不能。如果我的理解是正确的。请找截图。
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="test" doc:name="HTTP Listener Configuration"/>
<flow name="TestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<set-payload value="#['Hello World']" doc:name="Set Payload"/>
<exception-strategy ref="Choice_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<choice-exception-strategy name="Choice_Exception_Strategy">
<catch-exception-strategy when="exception.causeMatches(java.lang.ArithmeticException)" doc:name="Catch Exception Strategy- Arithmetic Exception">
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<catch-exception-strategy doc:name="Catch Exception Strategy-All Exception">
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
根据您的意见,您可以使用适合您的任何可行方法。
如果您使用的是旧版本。调色板看起来像这里提到的 url
https://docs.mulesoft.com/mule-user-guide/v/3.7/catch-exception-strategy
我们有一个要求,我们想要编写一个全局异常处理程序,以便这个全局异常处理程序捕获任何单个流(我们有 80 多个 mule 流)上的任何异常。
基本上我们想添加一个全局配置并关联一个默认的全局捕获异常策略,以便在这里处理任何流程中的任何异常。
每个流程添加每个 'catch exception strategy' 是可行的,但我必须重复类似的代码 50 多次,出于明显的原因我想避免。
此外,请注意我想将特定参数传递给此全局异常策略,以便此全局异常策略也提供流特定信息。请建议。
注意:我在 mule 'Global Elements' 中没有看到全局捕获异常策略选项 UI。
参考文献:
Mule 特定文档没有明确说明。
https://docs.mulesoft.com/mule-user-guide/v/3.7/error-handling
这个需求看起来很像,但是传参等不是很清楚:
How to add a global exception handler/logger once in Mule
star的建议不错。此外,如果您想将参数传递给全局异常处理程序,一个好的方法是设置一个全局异常读取的流变量,并且永远不要忘记在您拥有的每个流上将一个值放入该变量。
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="test" doc:name="HTTP Listener Configuration"/>
<flow name="TestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<set-payload value="#['Hello World']" doc:name="Set Payload"/>
<exception-strategy ref="Choice_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<choice-exception-strategy name="Choice_Exception_Strategy">
<catch-exception-strategy when="exception.causeMatches(java.lang.ArithmeticException)" doc:name="Catch Exception Strategy- Arithmetic Exception">
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<catch-exception-strategy doc:name="Catch Exception Strategy-All Exception">
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
根据您的意见,您可以使用适合您的任何可行方法。
如果您使用的是旧版本。调色板看起来像这里提到的 url https://docs.mulesoft.com/mule-user-guide/v/3.7/catch-exception-strategy