Mule 异常策略 Magento 库存输入
Mule Exception Strategy Magento Inventory Input
我有一个 Mule 流,它通过 SOAP API 更新 Magento Invtory。一切运行良好,直到我尝试更新不在 Magento 数据库中的项目。然后我得到一个例外。
ERROR 2016-06-17 12:31:06,523 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Product not exists.. Type: class org.apache.axis.AxisFault
我的异常策略是这样的:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causedExactlyBy(org.mule.api.MessagingException)]" doc:name="Catch Exception Strategy">
<logger message="error" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
我想要的结果是发生异常时记录它,但继续处理流程。
编辑:
我还尝试了以下异常策略:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
错误语法如下:
错误 2016-06-20 10:47:03,080 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
消息:调用 updateInventoryStockItem 失败。消息负载的类型为:String[]
类型:org.mule.api.MessagingException
代码:MULE_ERROR--2
有效载荷:[Ljava.lang.String;@191acd5
Java文档:http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
异常堆栈是:
1.产品不存在。 (org.apache.axis.AxisFault)
org.apache.axis.message.SOAPFaultBuilder:222(空)
2.产品不存在。 (org.mule.module.magento.api.MagentoException)
org.mule.module.magento.api.MagentoClientAdaptor:83 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/magento/api/MagentoException.html)
3. 未能调用updateInventoryStockItem。消息负载的类型为:String[] (org.mule.api.MessagingException)
org.mule.devkit.processor.DevkitBasedMessageProcessor:133 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
处理这种情况的最佳方法是流程设计。将 Magento 操作和异常策略放在自己的私有流中,并从另一个流中引用它。这样,异常将在私有流程中被捕获和处理,处理将 return 到主流程,您可以在主流程中继续做任何您想做的事情。例如:
<flow name="main-flow">
<flow-ref name="magento-flow" />
<logger level="INFO" message="This will continue processing" />
</flow>
<flow name="magento-flow">
<magento ... />
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
在 MagnetoFlow 中,使用 flowRef
使流程在数据库级别结束,其余逻辑将在下一个 flow.If 中继续,假设发生异常,它将被异常策略捕获。在这里您记录异常并继续使用 pendingLogic_MagnetoFlow
的流程 Ref。检查有效载荷是否可用于继续(因为如果流程从异常有效载荷继续可能不存在,则此处会流动),如果是这样,请使用您存储在会话变量中的 sessionVars 继续其他逻辑。
<flow name="magnetoFlow">
<set-session-variable variableName="originalPayload" value="#[payload]" doc:name="Session Variable"/>
---DB here----
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="Flow Reference"/>
<catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causeMatches(org.mule.api.*)]">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="pendingLogicFrom_MagnetoFlow"/>
</catch-exception-strategy>
</flow>
<flow name="pendingLogicFrom_MagnetoFlow">
<choice doc:name="Choice">
<when expression="#[check the payload is empty or not here ]">
<set-payload value="#[seesionVars.originalPayload]" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<logger level="INFO" doc:name="Logger"/>
---other normal logic here ---
</flow>
看看这个。
我有一个 Mule 流,它通过 SOAP API 更新 Magento Invtory。一切运行良好,直到我尝试更新不在 Magento 数据库中的项目。然后我得到一个例外。
ERROR 2016-06-17 12:31:06,523 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Product not exists.. Type: class org.apache.axis.AxisFault
我的异常策略是这样的:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causedExactlyBy(org.mule.api.MessagingException)]" doc:name="Catch Exception Strategy">
<logger message="error" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
我想要的结果是发生异常时记录它,但继续处理流程。 编辑: 我还尝试了以下异常策略:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
错误语法如下:
错误 2016-06-20 10:47:03,080 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
消息:调用 updateInventoryStockItem 失败。消息负载的类型为:String[] 类型:org.mule.api.MessagingException 代码:MULE_ERROR--2 有效载荷:[Ljava.lang.String;@191acd5 Java文档:http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
异常堆栈是: 1.产品不存在。 (org.apache.axis.AxisFault) org.apache.axis.message.SOAPFaultBuilder:222(空) 2.产品不存在。 (org.mule.module.magento.api.MagentoException) org.mule.module.magento.api.MagentoClientAdaptor:83 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/magento/api/MagentoException.html) 3. 未能调用updateInventoryStockItem。消息负载的类型为:String[] (org.mule.api.MessagingException) org.mule.devkit.processor.DevkitBasedMessageProcessor:133 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
处理这种情况的最佳方法是流程设计。将 Magento 操作和异常策略放在自己的私有流中,并从另一个流中引用它。这样,异常将在私有流程中被捕获和处理,处理将 return 到主流程,您可以在主流程中继续做任何您想做的事情。例如:
<flow name="main-flow">
<flow-ref name="magento-flow" />
<logger level="INFO" message="This will continue processing" />
</flow>
<flow name="magento-flow">
<magento ... />
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
在 MagnetoFlow 中,使用 flowRef
使流程在数据库级别结束,其余逻辑将在下一个 flow.If 中继续,假设发生异常,它将被异常策略捕获。在这里您记录异常并继续使用 pendingLogic_MagnetoFlow
的流程 Ref。检查有效载荷是否可用于继续(因为如果流程从异常有效载荷继续可能不存在,则此处会流动),如果是这样,请使用您存储在会话变量中的 sessionVars 继续其他逻辑。
<flow name="magnetoFlow">
<set-session-variable variableName="originalPayload" value="#[payload]" doc:name="Session Variable"/>
---DB here----
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="Flow Reference"/>
<catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causeMatches(org.mule.api.*)]">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="pendingLogicFrom_MagnetoFlow"/>
</catch-exception-strategy>
</flow>
<flow name="pendingLogicFrom_MagnetoFlow">
<choice doc:name="Choice">
<when expression="#[check the payload is empty or not here ]">
<set-payload value="#[seesionVars.originalPayload]" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<logger level="INFO" doc:name="Logger"/>
---other normal logic here ---
</flow>
看看这个。