为什么Mule异常策略这么聊天? [英] Why is Mule exception strategy so chatty?

查看:173
本文介绍了为什么Mule异常策略这么聊天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Mule应用程序中,我已经配置了一些流来使用catch异常策略来进行一些特殊的处理。对于这些情况,我想将错误和原始有效负载弹出到对象存储中。在其他地方,默认的异常策略很好。

In my Mule app, I've configured some of the flows to use a catch exception strategy in order to do some special processing. For these cases, I want to pop the error and the original payload into an object store. Everywhere else, the default exception strategy is fine.

<flow name="saveLookup">
    <vm:inbound-endpoint exchange-pattern="one-way"  ref="Lookup_Save_VM" />
    <component>
      <spring-object bean="insertLookupMDCvalues"/>
    </component>
    <set-variable variableName="originalPayload" value="#[payload]"/>
    <json:json-to-object-transformer returnClass="com.company.LookupData"/>
    <set-variable variableName="transactionId" value="#[payload.transactionId]"/>
    <transactional action="ALWAYS_BEGIN">
        <logger message="${lookup.SQL}" level="INFO"/>
        <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="saveLookup" queryTimeout="-1" connector-ref="JdbcConnector" />
        <foreach collection="#[payload.transactional.lookupItems.items]">
            <logger message="${lookup.item.SQL}" level="INFO" />
            <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="saveLookupItem" queryTimeout="-1" connector-ref="JdbcConnector"/>
        </foreach>
    </transactional>
    <component>
      <spring-object bean="clearLookupMDCvalues"/>
    </component>        
    <catch-exception-strategy>
        <message-properties-transformer scope="invocation">
            <add-message-property key="errorMap" value="#[['id' : transactionId, 'body' : originalPayload, 'error' : exception.summaryMessage]]"/>
        </message-properties-transformer>
        <choice>
            <when expression="#[message.inboundProperties['resubmit']]">
                <logger message="Resubmission of lookup data failed, saving to Dead Letter object store. ID=#[transactionId]" level="INFO"/>
                <objectstore:store config-ref="lookupDeadLetterOS" key="#[transactionId]" overwrite="true" value-ref="#[errorMap]"/>
            </when>
            <otherwise>
                <logger message="Saving lookup data failed, saving to Error object store. ID=#[transactionId]" level="INFO"/>
                <objectstore:store config-ref="lookupErrorOS" key="#[transactionId]" overwrite="true" value-ref="#[errorMap]"/>
            </otherwise>
        </choice>
        <set-payload value="Error: #[exception.summaryMessage]"/>
        <component>
          <spring-object bean="clearLookupMDCvalues"/>
        </component>                 
    </catch-exception-strategy>
</flow>

我的问题是当遇到错误时,让我们说foreach组件中的一个空指针异常,我看到每个事件有四个ERROR日志语句:

My problem is that when an error is encountered, let's say a Null Pointer Exception in the foreach component, I'm seeing four ERROR log statements for each event:


  • 异常堆栈是:1. null(java.lang.NullPointerException) > ...等等。这是两次记录。

  • CatchMessagingExceptionStrategy - 消息:执行表达式payload.transactional.lookupItems.items失败。 (org.mule.api.expression.ExpressionRuntimeException)。消息有效载荷类型为:LookupData

  • DefaultMessagingExceptionStrategy - 消息:表达式payload.transactional.lookupItems.items的执行失败。 (org.mule.api.expression.ExpressionRuntimeException)。消息有效载荷类型为:LookupData

我以为特定于流的异常策略应该覆盖默认策略。为什么重复日志消息,有没有办法捣蛋?我想避免必须配置默认的异常策略,因为它在大多数流中是完全可以接受的行为。

I thought that a flow-specific exception strategy should override the default strategy. Why the duplicate log messages, and is there a way to shush them? I'd like to avoid having to configure the default exception strategy, as it's perfectly acceptable behavior in the majority of the flows.

推荐答案

问题是内置的异常策略继承自 AbstractExceptionListener ,并且它们都使用 logException 模板方法。基本实现始终记录在ERROR级别,这有时不适合您的应用程序。

The issue is that the built in exception strategies inherit from AbstractExceptionListener, and they all use the logException template method. The base implementation always logs at ERROR level, which is sometimes not appropriate for your application.

您可以创建一个CatchMessagingExceptionStrategy的简单子类来覆盖logException方法,并记录你要。然后,在流程中使用它,代替< catch-exception-strategy> ,如下所示:

You can create a simple subclass of CatchMessagingExceptionStrategy that overrides the logException method, and logs however you want. Then, use it in your flow in place of the <catch-exception-strategy> like so:

<custom-exception-strategy class="com.mycompany.mule.QuietCatchExceptionStrategy">
    <!-- your message processors here -->
</custom-exception-strategy>

这篇关于为什么Mule异常策略这么聊天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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