redisstream

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxLen int64 = 10000

DefaultMaxLen 单流默认近似上限条数(Publish 时 MAXLEN ~)。

Variables

This section is empty.

Functions

func Infof

func Infof(format string, args ...any)

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus 基于 Backend 的 Redis Stream 风格事件总线(每 group 独立消费)。

func New

func New(be event.Backend, prefix string, opts ...Option) *Bus

New 创建总线。prefix 用于 stream key:{prefix}:{topic};空则用 "event"。 默认 WithMaxLen(DefaultMaxLen);可用 Option 覆盖。

func (*Bus) Consumer

func (b *Bus) Consumer(group, consumer string, opts ...ConsumerOption) *Consumer

Consumer 创建链式消费者。默认 handler 池 min=2 max=8(Run 时创建)。

func (*Bus) MaxLen

func (b *Bus) MaxLen() int64

MaxLen 当前单流近似上限(0 表示不裁剪)。

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, topic string, env event.Envelope) error

Publish 实现 event.Publisher。

func (*Bus) Subscribe

func (b *Bus) Subscribe(ctx context.Context, topic, group, consumer string, h event.Handler) error

Subscribe 实现 event.Subscriber。

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer 预注册多 topic 消费者:链式 On,Run 单循环多 Stream BLOCK 读。

func (*Consumer) On

func (c *Consumer) On(topic string, h event.Handler) *Consumer

On 注册 topic handler,返回自身以支持链式调用。

func (*Consumer) Run

func (c *Consumer) Run(ctx context.Context) error

Run 阻塞消费直到 ctx 取消。须至少 On 一个 topic。

type ConsumerOption

type ConsumerOption func(*Consumer)

ConsumerOption 配置 Consumer 的 handler 池等。

func WithHandlerPool

func WithHandlerPool(p *gopool.Pool) ConsumerOption

WithHandlerPool 使用外部工人池(生命周期由该池的 New ctx 管理)。

func WithHandlerWorkers

func WithHandlerWorkers(minSize, maxSize int) ConsumerOption

WithHandlerWorkers 使用内建动态池 min~max(在 Run 时用其 ctx 创建)。

type Option

type Option func(*Bus)

Option 配置 Bus。

func WithMaxLen

func WithMaxLen(n int64) Option

WithMaxLen 设置单流近似上限;0 关闭裁剪。未设置时用 DefaultMaxLen。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL