How to catch exceptions in the Mule foreach scope but keep the process going?

女生的网名这么多〃 提交于 2019-12-22 08:44:02

问题


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?

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>

回答1:


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>


来源:https://stackoverflow.com/questions/22825397/how-to-catch-exceptions-in-the-mule-foreach-scope-but-keep-the-process-going

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!