Documentation
¶
Index ¶
- type Consumer
- func (c *Consumer) Register(stream string, fn ConsumerFunc)
- func (c *Consumer) RegisterWithLastID(stream string, id string, fn ConsumerFunc)
- func (c *Consumer) RegisterWithLastIDContext(ctx context.Context, stream string, id string, fn ConsumerFunc)
- func (c *Consumer) Run()
- func (c *Consumer) RunContext(ctx context.Context)
- func (c *Consumer) Shutdown()
- type ConsumerFunc
- type ConsumerOptions
- type Message
- type Producer
- type ProducerOptions
- type RedisOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct {
// Errors 用于上报消费过程中的错误;通道带缓冲,避免无人监听时阻塞主流程。
Errors chan error
// contains filtered or unexported fields
}
Consumer Redis Stream 消费器。
func NewConsumerWithOptions ¶
func NewConsumerWithOptions(options *ConsumerOptions) (*Consumer, error)
NewConsumerWithOptions 使用自定义配置创建消费者。
func (*Consumer) Register ¶
func (c *Consumer) Register(stream string, fn ConsumerFunc)
Register 注册流消费处理函数。
func (*Consumer) RegisterWithLastID ¶
func (c *Consumer) RegisterWithLastID(stream string, id string, fn ConsumerFunc)
RegisterWithLastID 注册流消费处理函数,并指定首次建组时的起始消息 ID。
func (*Consumer) RegisterWithLastIDContext ¶
func (c *Consumer) RegisterWithLastIDContext(ctx context.Context, stream string, id string, fn ConsumerFunc)
RegisterWithLastIDContext 使用指定上下文注册流消费处理函数,并指定首次建组时的起始消息 ID。
func (*Consumer) RunContext ¶
RunContext 使用指定上下文启动消费者并阻塞,直到收到关闭信号或上下文取消。
type ConsumerOptions ¶
type ConsumerOptions struct {
Name string
GroupName string
VisibilityTimeout time.Duration
BlockingTimeout time.Duration
ReclaimInterval time.Duration
BufferSize int
Concurrency int
RedisOptions *RedisOptions
}
ConsumerOptions 消费者配置。
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer Redis Stream 生产者。
func NewProducerWithOptions ¶
func NewProducerWithOptions(options *ProducerOptions) (*Producer, error)
NewProducerWithOptions 使用自定义配置创建生产者。
type ProducerOptions ¶
type ProducerOptions struct {
// StreamMaxLength 对应 XADD 的 MAXLEN 配置,用于限制 Stream 总长度,避免消息无限增长占满内存。
// 这里限制的是 Stream 中的总消息数,而不是“已消费完成”的消息数。
// 如果消费者全部不可用但生产者仍在持续入队,达到上限后较早的未处理消息也可能被裁剪。
// 因此生产环境通常建议根据业务峰值将该值设置得更高。
StreamMaxLength int64
// ApproximateMaxLength 控制 MAXLEN 是否使用 `~` 近似裁剪,以换取更高的裁剪性能。
ApproximateMaxLength bool
// RedisOptions 底层 Redis 连接配置。
RedisOptions *RedisOptions
}
ProducerOptions 生产者配置。
type RedisOptions ¶
type RedisOptions = redis.UniversalOptions
RedisOptions 是 redis.UniversalOptions 的别名,便于调用方直接复用配置结构。
Click to show internal directories.
Click to hide internal directories.