redisstream

package
v0.0.0-...-4799099 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoSleep can be set to SubscriberConfig.NackResendSleep and SubscriberConfig.ReconnectRetrySleep
	NoSleep time.Duration = -1

	// Block to wait next redis stream message
	DefaultBlockTime time.Duration = time.Millisecond * 100

	// Claim idle pending message every 5 seconds
	DefaultClaimInterval time.Duration = time.Second * 5

	// Default max idle time for pending message.
	// After timeout, the message will be claimed and its idle consumer will be removed from consumer group
	DefaultMaxIdleTime time.Duration = time.Second * 60
)
View Source
const UUIDHeaderKey = "_watermill_message_uuid"

Variables

This section is empty.

Functions

func NewPublisher

func NewPublisher(ctx context.Context, config PublisherConfig, rc redis.UniversalClient, marshaller Marshaller, logger watermill.LoggerAdapter) (message.Publisher, error)

NewPublisher creates a new redis stream Publisher.

func NewSubscriber

func NewSubscriber(ctx context.Context, config SubscriberConfig, rc redis.UniversalClient, unmarshaller Unmarshaller, logger watermill.LoggerAdapter) (message.Subscriber, error)

NewSubscriber creates a new redis stream Subscriber

Types

type DefaultMarshaller

type DefaultMarshaller struct{}

func (DefaultMarshaller) Marshal

func (DefaultMarshaller) Marshal(_ string, msg *message.Message) (map[string]interface{}, error)

func (DefaultMarshaller) Unmarshal

func (DefaultMarshaller) Unmarshal(values map[string]interface{}) (msg *message.Message, err error)

type MarshalerUnmarshaler

type MarshalerUnmarshaler interface {
	Marshaller
	Unmarshaller
}

type Marshaller

type Marshaller interface {
	Marshal(topic string, msg *message.Message) (map[string]interface{}, error)
}

type Publisher

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

Publisher publishes messages to redis streams via XADD.

func (*Publisher) Close

func (p *Publisher) Close() error

func (*Publisher) Publish

func (p *Publisher) Publish(topic string, msgs ...*message.Message) error

Publish publishes message to redis stream

Publish is blocking and wait for redis response When one of messages delivery fails - function is interrupted.

type PublisherConfig

type PublisherConfig struct {
	Maxlens map[string]int64
}

func (*PublisherConfig) Validate

func (sc *PublisherConfig) Validate() error

type Subscriber

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

Subscriber subscribes to redis streams via XREAD or XREADGROUP

func (*Subscriber) Close

func (s *Subscriber) Close() error

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)

type SubscriberConfig

type SubscriberConfig struct {
	// Redis stream consumer id
	// Pair with ConsumerGroup
	Consumer string
	// When empty, fan-out mode will be used
	ConsumerGroup string

	// How long after Nack message should be redelivered
	NackResendSleep time.Duration

	// How long should we treat a consumer as offline
	MaxIdleTime time.Duration
}

func DefaultSubscriberConfig

func DefaultSubscriberConfig() SubscriberConfig

func (*SubscriberConfig) Validate

func (sc *SubscriberConfig) Validate() error

type Unmarshaller

type Unmarshaller interface {
	Unmarshal(values map[string]interface{}) (msg *message.Message, err error)
}

Jump to

Keyboard shortcuts

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