mq

package module
v0.0.0-...-5116708 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 1 Imported by: 11 modules, 9 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.

README

mq-api

消息队列的的 API 定义,准备提供多种实现

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	// Consume 获取单条信息
	Consume(ctx context.Context) (*Message, error)
	// ConsumeChan  从返回的channel中获取mq中的消息
	ConsumeChan(ctx context.Context) (<-chan *Message, error)
	// Close 用于释放资源,多次调用返回的error与第一次调用返回的error相同
	Close() error
}

Consumer 是消费者的抽象,用于从指定Topic接收/消费消息,可以被多个协程并发访问

type Header map[string]string

type MQ

type MQ interface {
	// CreateTopic 用于创建topic并使用partitions指定分区数。分区从0开始编号,例如分区数为4,那么分区号就是0-3
	CreateTopic(ctx context.Context, topic string, partitions int) error
	// DeleteTopics 用于删除一个或多个topic
	DeleteTopics(ctx context.Context, topics ...string) error
	// Producer 用于创建某个topic的生产者
	Producer(topic string) (Producer, error)
	// Consumer 用于创建某个topic的消费者并使用groupID指定消费者所属消费组
	Consumer(topic string, groupID string) (Consumer, error)
	// Close 用于关闭消息队列,释放所有建立的Producer和Consumer资源,多次调用返回的error与第一次调用返回的error相同
	// 返回的error为由MQ抽象创建的Consumer和Producer的Close方法返回的error拼接而成
	Close() error
}

MQ 是消息队列的抽象用于创建Topic、生产者及消费者,MQ可以被多个协程并发访问

type Message

type Message struct {
	// 消息本体,存储业务消息
	Value []byte
	// 对标kafka中的key,用于分区的。可以省略
	Key []byte
	// 对标kafka的header,用于传递一些自定义的元数据。
	Header Header
	// 消息主题
	Topic string
	// 分区ID
	Partition int64
	// 偏移量
	Offset int64
}

Message 是消息队列中传递的消息封装

type Producer

type Producer interface {
	// Produce 不指定分区发送消息,发送消息时,消息所在分区不确定
	Produce(ctx context.Context, m *Message) (*ProducerResult, error)
	// ProduceWithPartition 指定分区发送消息
	ProduceWithPartition(ctx context.Context, m *Message, partition int) (*ProducerResult, error)
	// Close 用于释放资源,多次调用返回的error与第一次调用返回的error相同
	Close() error
}

Producer 是生产者抽象,用于向指定Topic发送/生产消息,可以被多个协程并发访问

type ProducerResult

type ProducerResult struct{}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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