mqx

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	HeaderTenantID = "x-tenant-id"
	HeaderUserID   = "x-user-id"
	HeaderBizID    = "x-biz-id"
)

Variables

View Source
var ErrConsumerClosed = errors.New("message consumer is closed")

ErrConsumerClosed 表示封装器已经被服务主动关闭。

Functions

func ConsumeLoop added in v1.11.2

func ConsumeLoop(ctx context.Context, consume func(context.Context) error, onError func(error))

ConsumeLoop 运行事件消费者循环。 ResilientConsumer 负责 MQ 连接恢复;这里仅负责业务处理失败后的限速重试, 并保证服务停止时不会继续等待或再次调用业务处理函数。

func ConsumeMessage added in v1.11.1

func ConsumeMessage(ctx context.Context, consumer mq.Consumer) (context.Context, *mq.Message, error)

ConsumeMessage 消费原始 MQ 消息,并返回从消息头恢复后的业务上下文。

func ExtractContext added in v1.11.1

func ExtractContext(ctx context.Context, msg *mq.Message) context.Context

ExtractContext 从 mq.Message.Header 中提取租户 ID、用户 ID 和业务 ID,重新注入并返回新的 Context

func InjectContext added in v1.11.1

func InjectContext(ctx context.Context, msg *mq.Message)

InjectContext 提取 Context 中的租户 ID、用户 ID 和业务 ID,注入到 mq.Message.Header 中

func ProduceMessage added in v1.11.1

func ProduceMessage(ctx context.Context, producer mq.Producer, msg *mq.Message) (*mq.ProducerResult, error)

ProduceMessage 注入上下文元数据后发送原始 MQ 消息。

Types

type ConsumeFunc added in v1.11.1

type ConsumeFunc func(ctx context.Context, message *mq.Message) error

type Consumer added in v1.11.1

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

func NewConsumer added in v1.11.1

func NewConsumer(name string, mq mq.MQ, topic string) *Consumer

func (*Consumer) Name added in v1.11.1

func (c *Consumer) Name() string

func (*Consumer) Start added in v1.11.1

func (c *Consumer) Start(ctx context.Context, consumeFunc ConsumeFunc) error

func (*Consumer) Stop added in v1.11.1

func (c *Consumer) Stop() error

type GeneralProducer

type GeneralProducer[T any] struct {
	// contains filtered or unexported fields
}

func NewGeneralProducer

func NewGeneralProducer[T any](q mq.MQ, topic string) (*GeneralProducer[T], error)

func (*GeneralProducer[T]) Produce

func (p *GeneralProducer[T]) Produce(ctx context.Context, evt T) error

type MultipleProducer

type MultipleProducer[T any] struct {
	// contains filtered or unexported fields
}

MultipleProducer 管理多个 GeneralProducer

func NewMultipleProducer

func NewMultipleProducer[T any](mq mq.MQ) *MultipleProducer[T]

NewMultipleProducer 创建一个新的 ProducerManager

func (*MultipleProducer[T]) AddProducer

func (pm *MultipleProducer[T]) AddProducer(topic string) error

AddProducer 添加一个新的 producer 监听指定的 topic

func (*MultipleProducer[T]) Produce

func (pm *MultipleProducer[T]) Produce(ctx context.Context, topic string, evt T) error

Produce 发送消息到指定的 topic

type Producer

type Producer[T any] interface {
	Produce(ctx context.Context, evt T) error
}

type ResilientConsumer added in v1.11.2

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

ResilientConsumer 在 MQ Consumer 因长时间断网失效后负责退避重建。

func NewResilientConsumer added in v1.11.2

func NewResilientConsumer(q mq.MQ, topic, group string) *ResilientConsumer

func (*ResilientConsumer) Close added in v1.11.2

func (c *ResilientConsumer) Close() error

func (*ResilientConsumer) Consume added in v1.11.2

func (c *ResilientConsumer) Consume(ctx context.Context) (*mq.Message, error)

func (*ResilientConsumer) ConsumeChan added in v1.11.2

func (c *ResilientConsumer) ConsumeChan(ctx context.Context) (<-chan *mq.Message, error)

ConsumeChan keeps compatibility with mq.Consumer while retaining reconnect behavior.

Jump to

Keyboard shortcuts

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