Mule回滚异常策略中的maxRedeliveryAttempts无限运行

时间:2018-03-30 07:39:06

标签: mule mule-component mule-esb

我有一个骡流(模拟流),目前正在对几个微服务进行http调用。如果其中一个服务调用由于连接异常而失败,我有一个回滚异常策略配置为重新处理消息(发送到kafka,后者又调用模拟流)但重试似乎无限期地发生,尽管指定了maxRedeliveryAttempts属性。如何限制重试次数?任何帮助将不胜感激

<flow name="mock-flow">
    <logger level="INFO" message="CRD::: Calling Selldown settle Micro Service***"/>
    <logger message="CRD::: Response received : #[message.payload]" level="INFO" />
    <http:request config-ref="tp-ins-selldown-msConfig" path="/settle"
                method="POST" doc:name="HTTP">
                <http:success-status-code-validator
                    values="200,201" />
    </http:request>
    <http:request parseResponse="false" config-ref="tp-ins-limits-msConfig" path="booksdlimit"
            method="POST" doc:name="HTTP">
                <http:success-status-code-validator values="200,201"/>
    </http:request>             
    <choice-exception-strategy doc:name="Choice Exception Strategy">
        <rollback-exception-strategy when="exception.causedBy(java.net.ConnectException)" maxRedeliveryAttempts="2" doc:name="Rollback Exception Strategy">
            <logger message="Will attempt redelivery" level="INFO" doc:name="Logger" />
            <vm:outbound-endpoint exchange-pattern="one-way" path="kafka.inpath" doc:name="VM" />
            <on-redelivery-attempts-exceeded>
            <logger message="redelivery attempt exceeded" level="INFO" doc:name="Logger" />
                <logger message="Retry exhausted" level="INFO" doc:name="Logger" />
            </on-redelivery-attempts-exceeded>
        </rollback-exception-strategy>
    </choice-exception-strategy>

1 个答案:

答案 0 :(得分:0)

由于maxReDeliveryAttempts attrtibute没有工作(出于任何奇怪的原因),我必须自己(手动)通过配置一个带有消息请求的mule对象存储作为键并重试计数器作为值来完成它

    <rollback-exception-strategy when="exception.causedBy(java.net.ConnectException)" doc:name="Rollback Exception Strategy">
                <objectstore:retrieve config-ref="ObjectStore" key="#[uuid]" targetProperty="retryCounter" doc:name="Get value from ObjectStore" />
                <logger level="INFO" doc:name="Logger" message="Retry counter --------------> #[retryCounter]"/>
            <choice doc:name="Choice">
                <when expression="#[retryCounter > 3]">
                    <logger message="Retry exhausted" level="INFO" doc:name="Logger" />
                    <objectstore:remove key="#[uuid]" config-ref="ObjectStore" ignoreNotExists="true" doc:name="Remove the key after retry exhaust" />
                </when>
                <otherwise>
                    <expression-component>
                        Thread.sleep(3000);
                    </expression-component>
                    <logger message="Will attempt redelivery" level="INFO" doc:name="Logger" />
                    <transformer ref="ObjectToString"/>
                    <vm:outbound-endpoint exchange-pattern="one-way" path="kafka.inpath" doc:name="VM" />
                    <objectstore:remove key="#[uuid]" config-ref="ObjectStore" ignoreNotExists="true" doc:name="Remove if exists" />
                    <objectstore:store config-ref="ObjectStore" key="#[uuid]" value-ref="#[retryCounter + 1]" doc:name="Store new value" />
                </otherwise>
            </choice>
        </rollback-exception-strategy>

即使maxRedeliveryAttempts变量有效,似乎也没有帮助我的用例,因为当触发多个请求时,我们无法通过简单地依赖此属性来确保每个请求仅被重新触发3次(除非mule内部使用每个req的哈希码来确定它是否已被重新触发)

流量变量和会话变量在我的情况下也不起作用,因为重新触发点是kafka队列(没有被flow-ref手动调用)。因此必须使用对象存储