Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nak() should follow backoff #5856

Open
tamis-laan opened this issue Sep 3, 2024 · 4 comments
Open

nak() should follow backoff #5856

tamis-laan opened this issue Sep 3, 2024 · 4 comments
Labels
proposal Enhancement idea or proposal

Comments

@tamis-laan
Copy link

Proposed change

Make msg.nak() follow the set backoff strategy in the consumer.

Use case

Given the following:

# Backoff strategy
backoff = [2,4,8,16,32]

# Consumer configuration
config = ConsumerConfig(
    durable_name="action_workers",
    backoff=backoff,
    ack_wait=backoff[-1],
    max_deliver=len(backoff) + 1
)

# Subscribe
sub = await js.pull_subscribe("action.process.*", durable="action_workers", config=config)

while True:
    msgs = await sub.fetch(1)
    for msg in msgs:
        print(msg)
        msg.nak()

I would expect msg.nak() to make use of the backoff strategy. However backoff is only used for retries.

Contribution

No response

@tamis-laan tamis-laan added the proposal Enhancement idea or proposal label Sep 3, 2024
@Jarema
Copy link
Member

Jarema commented Sep 3, 2024

nak marks message for immediate redelivery, so it does not apply ack_wait, or backoff, which is used in case of user not sending back anything.

You can however specify nak(delay) to achieve what I think would solve your use case.

@dreo
Copy link

dreo commented Oct 19, 2024

@Jarema that seems to contradict the info in the official docs, which for backoff option says this:

A sequence of durations controlling the redelivery of messages on nak or acknowledgment timeout. Overrides ackWait. The sequence length must be less than or equal to MaxDelivery. If backoff is not set, a nak will result in immediate redelivery.

Can you clarify on how and when this option is supposed to work? I've spent some time trying to get it work without success until I've noticed this thread, so my understanding is that you are right and the docs are wrong. This however seem a little bit counterintuitive, as I can't see a reason why this should not be applied to NAKs too 🤔. Could you elaborate a bit on this? Thanks.

@aricart
Copy link
Member

aricart commented Oct 19, 2024

Docs are wrong - it is redelivery of acknowledgement timeouts.
I couldn't apply to NAK, the server would have to track each message NAK retries, to assign a different value. Depending on your client, you may have the ability to specify the number of seconds (or some other time unit) before the server should re-deliver it.

@dreo
Copy link

dreo commented Oct 19, 2024

I see. Thanks for a quick reply.

For anyone interested, you can use delay param for NAK together with delivery attempt number from message metadata (message.metadata.num_delivered) to perform exponential backoff (or any other strategy) by message receiver itself - at least for this NAK use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants