Mule流执行意外地在SMTP sendout中分解错误

时间:2013-05-29 18:28:13

标签: mule esb flow mule-studio

我想从SMTP端点捕获错误(例如,如果配置错误或服务器已关闭),当发生这种情况时,请阻止消息继续正常路径,而是进入异常流程。异常处理程序工作,消息路由到异常流。出乎意料的是,邮件是重复的,并且还会继续"正常"流动也是如此。我希望它只朝一个方向发展:如果成功发送电子邮件进入正常端点,如果sendout失败则进入异常端点。

在下面提供的示例中,smtp因UnknownHostException而失败,并且消息进入failureEndpoint但由于某种原因消息也会在outboundEndpoint中结束:

    

<mule><!-- namespaces omitted for readability -->
    <flow name="sample-flowFlow1" doc:name="sample-flowFlow1">
        <inbound-endpoint ref="inboundEndpoint" doc:name="AMQP Consumer"/>
        <smtp:outbound-endpoint host="foobaz" to="test@example.com" from="test@example.com" subject="test" responseTimeout="10000" doc:name="SMTP"/>
        <outbound-endpoint ref="outboundEndpoint" doc:name="AMQP Publisher"/>
        <exception-strategy ref="FailureNotification" doc:name="Publish failure notification" />
    </flow>

    <catch-exception-strategy name="FailureNotification">
        <flow-ref name="FailureNotificationFlow" doc:name="Flow Reference" />
    </catch-exception-strategy>
    <sub-flow name="FailureNotificationFlow" doc:name="FailureNotificationFlow">
        <outbound-endpoint ref="failureEndpoint" doc:name="Failure Endpoint"/>
    </sub-flow>
</mule>

当在inboundEndpoint上发布消息并且SMTP连接器在提供的示例中完成配置错误时,我希望仅在failureEndpoint中看到该消息,而不是在outboundEndpoint和failureEndpoint中。我该如何做到这一点?

Mule版本:3.4.0

2 个答案:

答案 0 :(得分:2)

在此流程中,您使用的是多个外围区域。流程不等待smtp的响应,并且仍然继续下一个出站 在进行出站之前,可以添加一个条件来检查smtp是否成功。

修改后的流程如下所示。试试这个。

<flow name="sample-flowFlow1" doc:name="sample-flowFlow1">
    <inbound-endpoint ref="inboundEndpoint" doc:name="AMQP Consumer"/>
    <flow-ref name="mailingFlow" ></flow-ref>       
    <choice>
        <when expression="#[flowVars['mailingSuccess'] == 'failure']">
            <logger level="INFO" message="Mailing failed"></logger>
        </when>
        <otherwise>
            <outbound-endpoint ref="outboundEndpoint" doc:name="AMQP Publisher"/>       
        </otherwise>
    </choice>                   
</flow>

<flow name="mailingFlow" processingStrategy="synchronous" >
    <smtp:outbound-endpoint host="foobaz" to="test@example.com" from="test@example.com" subject="test" responseTimeout="10000" doc:name="SMTP"/>
    <catch-exception-strategy name="FailureNotification">
        <set-variable variableName="mailingSuccess" value="failure" ></set-variable>
        <flow-ref name="FailureNotificationFlow" doc:name="Flow Reference" />        
    </catch-exception-strategy>
</flow>

<sub-flow name="FailureNotificationFlow" doc:name="FailureNotificationFlow">
    <outbound-endpoint ref="failureEndpoint" doc:name="Failure Endpoint"/>
</sub-flow>

希望这有帮助

答案 1 :(得分:0)

即使流量是同步的,也没有区别。 SMTP传输是异步/单向的骡子。因此,您无法从传输中获取状态以确定它是否成功并基于此路由流。如果您需要根据状态进行路由,最好编写电子邮件组件并将其嵌入流中。如果电子邮件组件抛出MessagingException,它将由错误处理程序流自动处理,并且不会执行出站端点。