【问题标题】:Catch Exception Strategy捕获异常策略
【发布时间】:2013-05-31 21:09:19
【问题描述】:

我的 Mule 工作室版本是: 版本:3.4.0 构建日期:201305141336

我对捕获异常策略感到困惑......也许我需要使用不同的策略。基本上我需要将数据写入文件。文件写入后,我想发送一封电子邮件以指示写入是否成功。 (如果有人在写入时打开了文件,则最有可能发生故障)。我最初尝试将一封电子邮件放在 catch 异常块中,但后来发生的事情是我收到了两封电子邮件;一个在 catch 块中,一个在流的末端。我试图创建一个包含电子邮件主题的变量,并在异常中更改值,但它似乎没有做任何事情。我仍然收到包含成功消息的电子邮件。

有人对如何使这项工作有一些建议吗?最终,我只想根据文件写入成功/失败发送不同的电子邮件。这是我的配置。我通过使用锁定文件的 Excel 打开目标文件导致失败。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <flow name="FileOpenExample" doc:name="FileOpenExample" >
<quartz:inbound-endpoint xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" jobName="fileOpenEx" cronExpression="0,30 * * ? * FRI" repeatInterval="0" repeatCount="2" responseTimeout="10000" doc:name="Quartz">
            <quartz:event-generator-job/>
        </quartz:inbound-endpoint>
        <set-payload value="Some Sample File Data" doc:name="Set File Data"/>
        <set-variable variableName="emailSubject" value="File Save Successful" doc:name="Variable"/>
        <file:outbound-endpoint path="C:\Temp\IntegrationTesting" outputPattern="Attributes.csv" responseTimeout="10000" doc:name="File"/>
        <set-payload value="This email was generated by a Mule process." doc:name="Set Email Body"/>
            <smtp:outbound-endpoint host="mail1.newpig.com" to="${email.toList}" subject="#[emailSubject]" responseTimeout="10000" doc:name="EmailSuccess"  />
        <catch-exception-strategy doc:name="Catch Exception Strategy" enableNotifications="false">
            <expression-transformer expression="#[emailSubject='Save Failed']" doc:name="Expression"/>
        </catch-exception-strategy>    </flow>
</mule>

【问题讨论】:

    标签: mule


    【解决方案1】:

    这个场景似乎更类似于之前的帖子。

    这里的流程发布到出站,然后继续流程,因为出站本质上是异步的。需要有一些东西可以让流程等待,然后根据状态继续进行。

    您可以在以下链接中找到之前的类似帖子和我的答案。

    Mule flow execution unexpectedly splits on error in SMTP sendout

    希望这会有所帮助。

    【讨论】:

    • 谢谢。那篇文章让我走上了正轨。我在这个过程中还有其他问题,但那是另一篇文章。
    猜你喜欢
    • 2019-09-25
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多