queue

package
v1.1.59 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsumerConfig added in v1.1.51

type ConsumerConfig struct {
	VisibilityTimeout int   `mapstructure:"visibilityTimeout"` // seconds
	BlockingTimeout   int   `mapstructure:"blockingTimeout"`   // seconds
	ReclaimInterval   int   `mapstructure:"reclaimInterval"`   // seconds
	BufferSize        int   `mapstructure:"bufferSize"`
	Concurrency       int   `mapstructure:"concurrency"`
	MaxDeliveries     int64 `mapstructure:"maxDeliveries"` // max reclaim attempts; 0 = unlimited
}

ConsumerConfig configures the stream consumer group.

type Memory

type Memory struct {
	PoolNum uint
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(poolNum uint) *Memory

NewMemory 内存模式

func (*Memory) Append

func (m *Memory) Append(message storage.Messager) error

func (*Memory) Register

func (m *Memory) Register(name string, f storage.ConsumerFunc)

func (*Memory) Run

func (m *Memory) Run()

func (*Memory) Shutdown

func (m *Memory) Shutdown()

func (*Memory) String

func (*Memory) String() string

type Message

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

Message is a standalone queue message with no external dependencies. Fields are unexported to enforce mutex-protected access.

func (*Message) GetErrorCount

func (m *Message) GetErrorCount() int

func (*Message) GetID

func (m *Message) GetID() string

func (*Message) GetPrefix

func (m *Message) GetPrefix() (prefix string)

func (*Message) GetStream

func (m *Message) GetStream() string

func (*Message) GetValues

func (m *Message) GetValues() map[string]interface{}

GetValues returns a shallow copy of the values map so callers cannot mutate the Message's internal state without going through setters.

func (*Message) SetErrorCount

func (m *Message) SetErrorCount(count int)

func (*Message) SetID

func (m *Message) SetID(id string)

func (*Message) SetPrefix

func (m *Message) SetPrefix(prefix string)

func (*Message) SetStream

func (m *Message) SetStream(stream string)

func (*Message) SetValues

func (m *Message) SetValues(values map[string]interface{})

type NSQ

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

func NewNSQ

func NewNSQ(addresses []string, cfg *nsq.Config, channelPrefix string) (*NSQ, error)

NewNSQ nsq模式 只能监听一个channel

func (*NSQ) Append

func (e *NSQ) Append(message storage.Messager) error

Append 消息入生产者

func (*NSQ) Register

func (e *NSQ) Register(name string, f storage.ConsumerFunc)

Register 监听消费者

func (*NSQ) Run

func (e *NSQ) Run()

func (*NSQ) Shutdown

func (e *NSQ) Shutdown()

func (NSQ) String

func (NSQ) String() string

String 字符串类型

type ProducerConfig added in v1.1.51

type ProducerConfig struct {
	StreamMaxLength      int64 `mapstructure:"streamMaxLength"`
	ApproximateMaxLength bool  `mapstructure:"approximateMaxLength"`
}

ProducerConfig configures the stream producer.

type Redis

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

Redis implements storage.AdapterQueue using native Redis Streams.

func NewRedis

func NewRedis(client *redis.Client, producerCfg *ProducerConfig, consumerCfg *ConsumerConfig) (*Redis, error)

NewRedis creates a Redis-backed queue adapter using a single client for both producer and consumer. For the three-client architecture, use NewRedisWithConsumer instead.

func NewRedisWithConsumer added in v1.1.51

func NewRedisWithConsumer(producerClient, consumerClient *redis.Client, producerCfg *ProducerConfig, consumerCfg *ConsumerConfig) (*Redis, error)

NewRedisWithConsumer creates a Redis-backed queue adapter with separate clients for producer and consumer. The producerClient is used for XADD (non-blocking), the consumerClient is used for XREADGROUP (blocking).

func (*Redis) Append

func (r *Redis) Append(message storage.Messager) error

func (*Redis) InitError added in v1.1.51

func (r *Redis) InitError() error

InitError returns the error from the most recent Run() call, or nil if the consumer started successfully. Since AdapterQueue.Run() has no return value, callers use this to detect startup failures:

r.Run()
if err := r.InitError(); err != nil { ... }

func (*Redis) Register

func (r *Redis) Register(name string, f storage.ConsumerFunc)

func (*Redis) Run

func (r *Redis) Run()

func (*Redis) Shutdown

func (r *Redis) Shutdown()

func (*Redis) String

func (*Redis) String() string

type StreamConsumer added in v1.1.51

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

StreamConsumer reads messages from a Redis Stream consumer group with at-least-once delivery semantics.

Three goroutine types:

  • poll(): XREADGROUP BLOCK — pushes messages into a buffered channel
  • reclaim(): periodic XPENDING + batch XCLAIM for timed-out messages
  • N*work(): calls the user callback, then XACK on success

func NewStreamConsumer added in v1.1.51

func NewStreamConsumer(client *redis.Client, stream, group string, cfg *ConsumerConfig, handler storage.ConsumerFunc) (*StreamConsumer, error)

NewStreamConsumer creates a consumer bound to the given stream and group.

func (*StreamConsumer) Errors added in v1.1.51

func (sc *StreamConsumer) Errors() <-chan error

Errors returns a read-only channel that surfaces consumer errors. The channel is buffered and never blocks the consumer — when full, errors are silently dropped. Callers MUST drain this channel (e.g. with a dedicated goroutine that logs/alerts) or errors will be lost.

func (*StreamConsumer) Run added in v1.1.51

func (sc *StreamConsumer) Run()

Run starts the poll, reclaim, and worker goroutines.

func (*StreamConsumer) Shutdown added in v1.1.51

func (sc *StreamConsumer) Shutdown()

Shutdown signals all goroutines to stop and waits for them to drain.

type StreamProducer added in v1.1.51

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

StreamProducer publishes messages to Redis Streams.

func NewStreamProducer added in v1.1.51

func NewStreamProducer(client *redis.Client, cfg *ProducerConfig) *StreamProducer

NewStreamProducer creates a producer that writes to Redis Streams via XADD.

func (*StreamProducer) Send added in v1.1.51

func (p *StreamProducer) Send(ctx context.Context, stream string, values map[string]interface{}) (string, error)

Send adds a message to the given stream using XADD.

Jump to

Keyboard shortcuts

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