我的 Mule studio 版本是:版本:3.4.0 buildDate: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>