ActiveMQ Artemis的”max-redelivery-delay”和”deadletterqueue”。

huangapple go评论47阅读模式
英文:

ActiveMQ Artemis max-redelivery-delay and deadletterqueue

问题

我们正在使用 ActiveMQ Artemis 2.26.0 作为代理,我正在尝试在队列上设置一个重试机制。

我希望某些消息最多在 72 小时内进行逐渐增加的重试。超过 72 小时后,消息应该被发送到 DLQ(死信队列)。

文档 中指出,可以将消息重试机制和死信队列机制结合使用,因此我尝试了以下配置,使用了 ActiveMQ Artemis 提供的示例:

broker.xml:

      <address-settings>
         <!-- 覆盖示例队列的重试延迟 -->
         <address-setting match="exampleQueue">
            <redelivery-delay>30000</redelivery-delay>
            <redelivery-delay-multiplier>2.5</redelivery-delay-multiplier>
            <dead-letter-address>deadLetterQueue</dead-letter-address>
            <max-redelivery-delay>259200000</max-redelivery-delay>
         </address-setting>
      </address-settings>

      <addresses>
         <address name="deadLetterQueue">
            <anycast>
               <queue name="deadLetterQueue"/>
            </anycast>
         </address>
         <address name="exampleQueue">
            <anycast>
               <queue name="exampleQueue"/>
            </anycast>
         </address>
      </addresses>

看起来,使用这个配置后,消息在经过 10 次重试后会被发送到 deadLetterQueue(默认的 max-delivery-attempts 值)。

如何组合这些值以适应我的场景呢?

英文:

We are using the broker ActiveMQ Artemis 2.26.0, and I'm trying to set up a redelivery mechanism on a queue.

I would like for some messages to be retried for 72h maximum with progressive back-off. After 72h the message should be sent to a DLQ.

The doc states that both mechanisms of message redelivery and dead-letter queue can be combined, so I tried the following, using the examples provided with ActiveMQ Artemis:

broker.xml:

      &lt;address-settings&gt;
         &lt;!--override the redelivery-delay  for the example queue--&gt;
         &lt;address-setting match=&quot;exampleQueue&quot;&gt;
            &lt;redelivery-delay&gt;30000&lt;/redelivery-delay&gt;
            &lt;redelivery-delay-multiplier&gt;2.5&lt;/redelivery-delay-multiplier&gt;
            &lt;dead-letter-address&gt;deadLetterQueue&lt;/dead-letter-address&gt;
            &lt;max-redelivery-delay&gt;259200000&lt;/max-redelivery-delay&gt;
         &lt;/address-setting&gt;
      &lt;/address-settings&gt;

      &lt;addresses&gt;
         &lt;address name=&quot;deadLetterQueue&quot;&gt;
            &lt;anycast&gt;
               &lt;queue name=&quot;deadLetterQueue&quot;/&gt;
            &lt;/anycast&gt;
         &lt;/address&gt;
         &lt;address name=&quot;exampleQueue&quot;&gt;
            &lt;anycast&gt;
               &lt;queue name=&quot;exampleQueue&quot;/&gt;
            &lt;/anycast&gt;
         &lt;/address&gt;
      &lt;/addresses&gt;

It seems that with this configuration the message are sent to deadLetterQueue after 10 redeliveries (default value of max-delivery-attempts).

How do I combine these values to fit my scenario?

答案1

得分: 0

您需要将max-delivery-attempts的值设置为大于10。

总交付延迟是一个几何级数,因此它是<redelivery-delay>*(1-<redelivery-delay-multiplier>^<max-delivery-attempts>)/(1-<redelivery-delay-multiplier>)

在您的情况下,总交付延迟为30000*(1-2.5^10)/(1-2.5)=190714863,这小于72小时(259200000),因此为了适应您的情景,您需要将max-delivery-attempts的值设置为大于10,即max-delivery-attempts = 11时,总交付延迟为476817158(132小时),大于72小时。

英文:

TL; DR; you need to set a max-delivery-attempts value greater then 10

The total delivery delay is a geometric series so it is &lt;redelivery-delay&gt;*(1-&lt;redelivery-delay-multiplier&gt;^&lt;max-delivery-attempts&gt;)/(1-&lt;redelivery-delay-multiplier&gt;)

In your case the total delivery delay is 30000*(1-2.5^10)/(1-2.5)=190714863 that is less then 72h (259200000) so to fit your scenario you need to set a max-delivery-attempts value greater then 10, i.e. with max-delivery-attempts = 11 the total delivery delay is 476817158 (132h) that is greater than 72h.

答案2

得分: -2

要在ActiveMQ Artemis 2.26.0队列上设置一个重新投递机制,以最多重试消息72小时,采用渐进式退避,然后将消息发送到死信队列(DLQ),您可以使用以下配置:

<address-settings>
   <address-setting match="exampleQueue">
      <redelivery-delay>30000</redelivery-delay>
      <redelivery-delay-multiplier>2</redelivery-delay-multiplier>
      <max-redelivery-delay>259200000</max-redelivery-delay>
      <max-delivery-attempts>0</max-delivery-attempts>
      <dead-letter-address>deadLetterQueue</dead-letter-address>
      <expiry-delay>259200000</expiry-delay>
   </address-setting>
</address-settings>

<addresses>
   <address name="deadLetterQueue">
      <anycast>
         <queue name="deadLetterQueue"/>
      </anycast>
   </address>
   <address name="exampleQueue">
      <anycast>
         <queue name="exampleQueue"/>
      </anycast>
   </address>
</addresses>

配置说明:

  • redelivery-delay: 设置重新投递尝试之间的初始延迟,单位为毫秒。在此示例中,设置为30,000毫秒(30秒)。
  • redelivery-delay-multiplier: 设置随着时间的推移重新投递尝试之间的延迟增加速率。在此示例中,设置为2,这意味着每次重新投递尝试后延迟时间将翻倍。
  • max-redelivery-delay: 设置重新投递尝试之间的最大延迟,单位为毫秒。在此示例中,设置为259,200,000毫秒(72小时)。
  • max-delivery-attempts: 设置消息可以被重新投递的最大次数。在此示例中,设置为0,表示没有重新投递尝试次数的限制。
  • dead-letter-address: 设置DLQ的地址,当消息超过最大重新投递尝试次数或最大重新投递时间时,消息将被发送到该地址。
  • expiry-delay: 设置在多少毫秒后未被消耗的消息将自动过期并发送到DLQ。在此示例中,它与max-redelivery-delay设置为相同的值。

使用这个配置,消息将采用渐进式退避方式最多重试72小时,或者在被消耗之前,然后如果它们在那段时间内未被消耗,将被发送到DLQ。没有重新投递尝试次数的限制,因此重新投递尝试之间的延迟将继续增加,直到达到最大延迟。

英文:

To set up a redelivery mechanism on a queue in ActiveMQ Artemis 2.26.0 that retries messages for a maximum of 72 hours with progressive back-off, and then sends the message to a dead-letter queue (DLQ), you can use the following configuration:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;address-settings&gt;
   &lt;address-setting match=&quot;exampleQueue&quot;&gt;
      &lt;redelivery-delay&gt;30000&lt;/redelivery-delay&gt;
      &lt;redelivery-delay-multiplier&gt;2&lt;/redelivery-delay-multiplier&gt;
      &lt;max-redelivery-delay&gt;259200000&lt;/max-redelivery-delay&gt;
      &lt;max-delivery-attempts&gt;0&lt;/max-delivery-attempts&gt;
      &lt;dead-letter-address&gt;deadLetterQueue&lt;/dead-letter-address&gt;
      &lt;expiry-delay&gt;259200000&lt;/expiry-delay&gt;
   &lt;/address-setting&gt;
&lt;/address-settings&gt;

&lt;addresses&gt;
   &lt;address name=&quot;deadLetterQueue&quot;&gt;
      &lt;anycast&gt;
         &lt;queue name=&quot;deadLetterQueue&quot;/&gt;
      &lt;/anycast&gt;
   &lt;/address&gt;
   &lt;address name=&quot;exampleQueue&quot;&gt;
      &lt;anycast&gt;
         &lt;queue name=&quot;exampleQueue&quot;/&gt;
      &lt;/anycast&gt;
   &lt;/address&gt;
&lt;/addresses&gt;

<!-- end snippet -->

Explanation of the configuration:
redelivery-delay: This sets the initial delay between redelivery attempts in milliseconds. In this example, it is set to 30,000ms (30 seconds).
redelivery-delay-multiplier: This sets the rate at which the delay between redelivery attempts increases over time. In this example, it is set to 2, which means that the delay will double after each redelivery attempt.
max-redelivery-delay: This sets the maximum delay between redelivery attempts in milliseconds. In this example, it is set to 259,200,000ms (72 hours).
max-delivery-attempts: This sets the maximum number of times a message can be redelivered before being sent to the DLQ. In this example, it is set to 0, which means that there is no limit to the number of redelivery attempts.
dead-letter-address: This sets the address of the DLQ where messages that have exceeded the maximum number of redelivery attempts or the maximum time for redelivery are sent.
expiry-delay: This sets the time in milliseconds after which messages that have not been consumed are automatically expired and sent to the DLQ. In this example, it is set to the same value as max-redelivery-delay.
With this configuration, messages will be retried with progressive back-off for a maximum of 72 hours or until they are consumed, and then sent to the DLQ if they have not been consumed by that time. There is no limit to the number of redelivery attempts, so the delay between attempts will continue to increase until the maximum delay is reached.

huangapple
  • 本文由 发表于 2023年2月10日 16:43:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定