如何在Mule foreach范围内捕获异常,但保持流程正常进行? [英] How to catch exceptions in the Mule foreach scope but keep the process going?

查看:144
本文介绍了如何在Mule foreach范围内捕获异常,但保持流程正常进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Mule ESB的新手.我创建了一个简单的流程,该流程遍历订单列表,并调用Magento API逐一更新订单状态.我的问题是,如果在foreach范围内发生任何异常,则整个过程将排在最前面.我试图使用异常策略"来捕获异常,但它确实捕获了异常.但是如何恢复该过程呢?我没有在Google搜索中找到太多信息.也许我在流程方面做错了.我们通常如何在Mule中处理此问题?

I am new to Mule ESB. I have created a simple flow that loops through a list of orders and calls the Magento API to update the order statuses one by one. My problem is that if there are any exception occurs in the foreach scope, the whole process tops. I tried to use the Exception Strategy to capture the exception and it did capture the exception. But how to resume the process? I didn't find much info with google search. Maybe I was doing something wrong with the flow. How do we normally handle this in Mule?

这是我在xml中的流程.

Here is my flow in xml.

    <flow name="Update_Magento_Order_Status_AU" doc:name="Update_Magento_Order_Status_AU" initialState="started">
    <poll doc:name="Poll">
        <fixed-frequency-scheduler frequency="10" timeUnit="MINUTES"/>
        <jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="GET_ORDERS_BY_STATUS_QUERY" queryTimeout="-1" connector-ref="DSEDatabase" doc:name="Get Orders By Status"/>
    </poll>
    <flow-ref name="ProcessOrderStastusUpdate" doc:name="Process Order Status Update"/>
</flow>
<flow name="ProcessOrderStastusUpdate" doc:name="ProcessOrderStastusUpdate">
    <foreach collection="#[payload]" doc:name="For Each">
        <component doc:name="Set Magento Order Status for Update">
            <singleton-object class="com.dse.esb.component.OrderStatusMapperComp">
                <property key="as400OrderStatuses" value="${as400.orderstatuses}"/>
                <property key="magentoOrderStatuses" value="${magento.orderStatuses}"/>
            </singleton-object>
        </component>
        <logger message="About to update Magento Order Status" level="INFO" doc:name="Logger"/>
        <magento:add-order-comment config-ref="Magento" comment="Updated by Mule ESB with AS400 order status: #[payload.TRNSTS]" orderId="#[payload.EPGORDNBR]" status="#[flowVars['magentoOrderStatus']]" doc:name="Update Magento Order Status"/>
    </foreach>
    <choice-exception-strategy doc:name="Choice Exception Strategy">
        <catch-exception-strategy doc:name="default">
            <logger message="Handle default exception" level="INFO" category="==============&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;" doc:name="Logger"/>
        </catch-exception-strategy>
    </choice-exception-strategy>
</flow>

推荐答案

使用专用的流及其自己的异常策略处理for-each的内容.异常将在私有流中处理,并且父流应该能够继续.像这样:

Use a private flow for the content of the for-each with its own exception strategy. THe exception will be handled in the private flow and the parent flow should be able to continue. Something like:

<flow name="ProcessOrderStastusUpdate">
   <foreach collection="#[payload]" doc:name="For Each">
      <flow-ref name="privateFlow" />    
   </foreach>
</flow>

<flow name="privateFlow">
   <component doc:name="Set Magento Order Status for Update">
      <singleton-object class="com.dse.esb.component.OrderStatusMapperComp">
             <property key="as400OrderStatuses" value="${as400.orderstatuses}"/>
             <property key="magentoOrderStatuses" value="${magento.orderStatuses}"/>
      </singleton-object>
   </component>
   <logger message="About to update Magento Order Status" level="INFO" doc:name="Logger"/>
   <magento:add-order-comment config-ref="Magento" comment="Updated by Mule ESB with AS400 order status: #[payload.TRNSTS]" orderId="#[payload.EPGORDNBR]" status="#[flowVars['magentoOrderStatus']]" doc:name="Update Magento Order Status"/>


    <choice-exception-strategy doc:name="Choice Exception Strategy">
        <catch-exception-strategy doc:name="default">
            <logger message="Handle default exception" level="INFO" category="==============&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;" doc:name="Logger"/>
        </catch-exception-strategy>
    </choice-exception-strategy>
</flow>

这篇关于如何在Mule foreach范围内捕获异常,但保持流程正常进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆