Documentation
¶
Overview ¶
Package redisq provides a Redis Stream based message queue.
Index ¶
- Constants
- Variables
- func MustAddBatchHandler[T any](c *Consumer, r *Route, h func(ctx Context, ms []*M[T]) error)
- func MustAddHandler[T any](c *Consumer, r *Route, h func(ctx Context, m *M[T]) error)
- func Publish[T any](ctx context.Context, rdb *redis.Client, stream string, m *M[T]) error
- type Consumer
- type Context
- type Handler
- type M
- type Middleware
- type Option
- type RM
- type Route
Constants ¶
View Source
const (
MIMEJSON = "application/json"
)
Variables ¶
View Source
var ErrPanicked = errors.New("panicked")
ErrPanicked is a sentinel error for panics.
View Source
var (
MaxLen int64 = 10000 // See the README about details
)
Functions ¶
func MustAddBatchHandler ¶
func MustAddHandler ¶
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer is Redis Stream based message queue.
func NewConsumer ¶
func (*Consumer) MustAddRoute ¶
type Context ¶
type Context interface {
context.Context
WithContext(context.Context) Context
Route() Route
// IsBatch returns true if the route is batch.
IsBatch() bool
// Msg returns the first message in the current context.
Msg() RM
// Msgs returns all messages in the current context.
Msgs() []RM
// Ack acknowledge the messages.
// If no IDs are provided, all messages will be acknowledged when error is nil.
Ack(ids ...string)
// contains filtered or unexported methods
}
type Middleware ¶
func Chain ¶
func Chain(m ...Middleware) Middleware
Chain creates a single Middleware by chaining multiple Middleware functions.
func Recover ¶
func Recover(l *slog.Logger) Middleware
func Tracing ¶
func Tracing() Middleware
type Option ¶
type Option func(*Consumer)
func WithMiddlewares ¶
func WithMiddlewares(mws ...Middleware) Option
type Route ¶
type Route struct {
Stream string
Group string
PendingID string // The start ID for pending messages, default is "0"
Handler Handler // Handler is the message handler
NoPending bool // NoPending ignores the pending messages
BatchSize int64 // BatchSize specifies the number of messages fetched per batch
MaxLen int64 // MaxLen specifies the max length of current stream
}
Click to show internal directories.
Click to hide internal directories.