goRedisMQ/option.go
2025-03-27 17:30:19 +08:00

60 lines
1.5 KiB
Go

package redisMq
import "time"
type ProducerOptions struct {
msgQueueLen int64
}
type ProducerOption func(*ProducerOptions)
func WithMsgQueueLen(msgQueueLen int64) ProducerOption {
return func(o *ProducerOptions) {
o.msgQueueLen = msgQueueLen
}
}
type ConsumerOptions struct {
// 每轮接收消息的超时时长
receiveTimeout time.Duration
// 处理消息的最大重试次数,超过此次数时,消息会被投递到死信队列
maxRetryLimit int
// 死信队列,可以由使用方自定义实现
deadLetterMailbox DeadLetterMailbox
// 投递死信流程超时阈值
deadLetterDeliverTimeout time.Duration
// 处理消息流程超时阈值
handleMsgTimeout time.Duration
}
type ConsumerOption func(*ConsumerOptions)
func WithReceiveTimeout(receiveTimeout time.Duration) ConsumerOption {
return func(o *ConsumerOptions) {
o.receiveTimeout = receiveTimeout
}
}
func WithMaxRetryLimit(maxRetryLimit int) ConsumerOption {
return func(o *ConsumerOptions) {
o.maxRetryLimit = maxRetryLimit
}
}
func WithDeadLetterMailbox(deadLetterMailbox DeadLetterMailbox) ConsumerOption {
return func(o *ConsumerOptions) {
o.deadLetterMailbox = deadLetterMailbox
}
}
func WithDeadLetterDeliverTimeout(deadLetterDeliverTimeout time.Duration) ConsumerOption {
return func(o *ConsumerOptions) {
o.deadLetterDeliverTimeout = deadLetterDeliverTimeout
}
}
func WithHandleMsgTimeout(handleMsgTimeout time.Duration) ConsumerOption {
return func(o *ConsumerOptions) {
o.handleMsgTimeout = handleMsgTimeout
}
}