redispub

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package redispub provides a Redis Stream publisher using Watermill message bus.

This package wraps Watermill's Redis Stream publisher to provide event publishing with configurable timeout and error handling. It uses Redis Streams as the underlying transport for reliable message delivery.

Basic usage:

publisher, err := redispub.New(redisClient, &redispub.Config{
    Timeout: 5 * time.Second,
})
if err != nil {
    log.Fatal(err)
}
defer publisher.Close()

msg := &message.Message{
    UUID:    uuid.New().String(),
    Payload: []byte(`{"event":"user.created"}`),
}
err = publisher.Publish(ctx, "events", msg)

Messages are published to Redis Stream keys which can be consumed by subscribers. The Watermill framework provides automatic marshaling, error handling, and routing.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPublisherInitialization = errors.New("publisher: failed to initialize redis stream publisher")
	ErrPublishFailed           = errors.New("publisher: failed to publish messages")
	ErrNilRedisClient          = errors.New("publisher: redis client is required")
	ErrInvalidMaxStreamEntries = errors.New("publisher: maxStreamEntries cannot be negative")
)

Functions

func OlderStreamID added in v1.8.0

func OlderStreamID(left, right string) bool

OlderStreamID reports whether the left stream id precedes the right one. Ids have the form "<milliseconds>-<sequence>" and both parts have to be read as numbers: "9999999999999-0" sorts after "10000000000000-0" as a string.

func StreamIDAt added in v1.8.0

func StreamIDAt(instant time.Time) string

StreamIDAt is the lowest stream id an entry created at the given instant can carry. Redis derives ids from the wall clock, so an age-based retention bound is expressed as the id at the cutoff rather than as separate bookkeeping.

Types

type Options

type Options struct {
	MaxStreamEntries int64
	Timeout          time.Duration
	Logger           watermill.LoggerAdapter
}

type Publisher

type Publisher interface {
	PublishToTopic(ctx context.Context, topic string, messageContents ...string) error
	Close() error
}

type RedisPublisher

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

func New

func New(redisClient goredis.UniversalClient, opts Options) (*RedisPublisher, error)

func (*RedisPublisher) Close

func (p *RedisPublisher) Close() error

func (*RedisPublisher) PublishToTopic

func (p *RedisPublisher) PublishToTopic(ctx context.Context, topic string, messageContents ...string) error

Jump to

Keyboard shortcuts

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