Browse Source

Merge pull request #191 from taki-mekhalfa/feat/add_queue_message_expiration_option_for_the_consumer

feat: add queue message expiration option for consumer
main
Lane Wagner 5 months ago
committed by GitHub
parent
commit
0958e3a881
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      consumer_options.go

+ 15
- 0
consumer_options.go View File

@ -1,6 +1,8 @@
package rabbitmq
import (
"time"
amqp "github.com/rabbitmq/amqp091-go"
"github.com/wagslane/go-rabbitmq/internal/logger"
)
@ -329,3 +331,16 @@ func WithConsumerOptionsQueueQuorum(options *ConsumerOptions) {
options.QueueOptions.Args["x-queue-type"] = "quorum"
}
// WithConsumerOptionsQueueMessageExpiration sets the message expiration (TTL) for all messages in the queue.
// This option defines how long a message can remain in the queue before it is discarded if not consumed.
// The TTL is specified as a time.Duration and will be converted to milliseconds for RabbitMQ.
// See https://www.rabbitmq.com/docs/ttl#per-queue-message-ttl
func WithConsumerOptionsQueueMessageExpiration(ttl time.Duration) func(*ConsumerOptions) {
return func(options *ConsumerOptions) {
if options.QueueOptions.Args == nil {
options.QueueOptions.Args = Table{}
}
options.QueueOptions.Args["x-message-ttl"] = ttl.Milliseconds()
}
}

Loading…
Cancel
Save