Skip to content

SQS: Heartbeat for long-running handlers #1554

@chase-miller

Description

@chase-miller

Type: Feature

Is your feature request related to a problem? Please describe.
Without a heartbeat / keep-alive mechanism, a given message may be picked up multiple times by handlers (if it is long-running with variable time) and executed concurrently.

Describe the solution you'd like
A new SqsListener.UseHeartbeat property that - when set to true - keeps a given sqs message alive by extending its (in)visibility in the background.

Describe alternatives you've considered
An alternative is to inject an Visibility instance and do this manually in each handler.

Additional context
Implementing a heartbeat is recommended by AWS.

Implement a heartbeat mechanism to periodically extend the visibility timeout, ensuring the message remains invisible until processing is complete.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html#visibility-timeout-best-practices

As an aside, we've implemented this pattern in C# using a background thread (via Task.Run()) that stops a heartbeat and manages failures via CancellationTokens. This has proven effective.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions