【问题标题】:maxRedeliveryAttempts in Mule rollback exception strategy runs infinitelyMule回滚异常策略中的maxRedeliveryAttempts无限运行
【发布时间】:2018-03-30 07:39:05
【问题描述】:

我有一个 mule 流(模拟流),它当前对几个微服务进行 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>

【问题讨论】:

    标签: mule mule-component mule-esb


    【解决方案1】:

    由于 maxReDeliveryAttempts 属性不起作用(无论出于什么奇怪的原因),我必须自己(手动)通过配置一个 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内部为每个请求使用一个哈希码来确定它是否已经被重新触发)

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

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多