Documentation ¶
Overview ¶
abpxx6d04wxr 包含队列接口的定义
Index ¶
- Variables
- type Callback
- type Config
- type DelayingQueue
- type FakeDelayingQueue
- type Group
- type MessageHandleFunc
- type Pipeline
- func (pl *Pipeline) GetWorkerNumber() int64
- func (pl *Pipeline) Stop()
- func (pl *Pipeline) Submit(msg any) error
- func (pl *Pipeline) SubmitAfter(msg any, delay time.Duration) error
- func (pl *Pipeline) SubmitAfterWithFunc(fn MessageHandleFunc, msg any, delay time.Duration) error
- func (pl *Pipeline) SubmitWithFunc(fn MessageHandleFunc, msg any) error
- type Queue
Constants ¶
This section is empty.
Variables ¶
var ( // 默认的消息处理函数,返回接收到的消息和nil错误 // Default message handle function, returns the received message and a nil error DefaultMsgHandleFunc = func(msg any) (any, error) { return msg, nil } )
var ErrorQueueClosed = errors.New("pipeline is closed")
定义一个错误类型 ErrorQueueClosed,表示管道已经关闭 Define an error type ErrorQueueClosed, indicating that the pipeline is closed
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback = interface { // OnBefore 是一个方法,它在消息处理之前被调用,接收一个任意类型的参数 msg // OnBefore is a method that is called before message processing, it receives an argument of any type, msg OnBefore(msg any) // OnAfter 是一个方法,它在消息处理之后被调用,接收三个任意类型的参数:msg,result 和 err // OnAfter is a method that is called after message processing, it receives three arguments of any type: msg, result, and err OnAfter(msg, result any, err error) }
Callback 是一个接口,定义了在消息处理前后需要调用的方法 Callback is an interface that defines methods to be called before and after message processing
func NewEmptyCallback ¶ added in v0.1.4
func NewEmptyCallback() Callback
NewEmptyCallback 是一个函数,它创建并返回一个新的 emptyCallback NewEmptyCallback is a function that creates and returns a new emptyCallback
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config 是一个结构体,用于配置消息处理的参数 Config is a struct used to configure parameters for message processing
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig 创建一个默认的配置 DefaultConfig creates a default configuration
func NewConfig ¶
func NewConfig() *Config
NewConfig 是一个函数,用于创建并返回一个新的 Config 结构体的指针 NewConfig is a function that creates and returns a pointer to a new Config struct
func (*Config) WithCallback ¶
WithCallback 是一个方法,用于设置 Config 结构体中的 callback 变量 WithCallback is a method used to set the callback variable in the Config struct
func (*Config) WithHandleFunc ¶
func (c *Config) WithHandleFunc(fn MessageHandleFunc) *Config
WithHandleFunc 是一个方法,用于设置 Config 结构体中的 handleFunc 变量 WithHandleFunc is a method used to set the handleFunc variable in the Config struct
func (*Config) WithResult ¶
WithResult 是一个方法,用于设置 Config 结构体中的 result 变量 WithResult is a method used to set the result variable in the Config struct
func (*Config) WithWorkerNumber ¶
WithWorkerNumber 是一个方法,用于设置 Config 结构体中的 num 变量 WithWorkerNumber is a method used to set the num variable in the Config struct
type DelayingQueue ¶ added in v0.2.0
type DelayingQueue = interface { Queue // PutWithDelay 方法用于将元素延迟放入队列。 // The PutWithDelay method is used to put an element into the queue with delay. PutWithDelay(value interface{}, delay int64) error }
DelayingQueue 接口继承了 Queue 接口,并添加了一个 PutWithDelay 方法,用于将元素延迟放入队列。 The DelayingQueue interface inherits from the Queue interface and adds a PutWithDelay method to put an element into the queue with delay.
type FakeDelayingQueue ¶ added in v0.1.4
type FakeDelayingQueue struct{ Queue }
FakeDelayingQueue 是一个结构体,它实现了 DelayingQueueInterface 接口,但是它的 AddAfter 方法实际上并不会延迟添加元素 FakeDelayingQueue is a struct that implements the DelayingQueueInterface interface, but its AddAfter method does not actually delay adding values
func NewFakeDelayingQueue ¶ added in v0.1.4
func NewFakeDelayingQueue(queue Queue) *FakeDelayingQueue
NewFakeDelayingQueue 是一个函数,它创建并返回一个新的 FakeDelayingQueue NewFakeDelayingQueue is a function that creates and returns a new FakeDelayingQueue
func (*FakeDelayingQueue) PutWithDelay ¶ added in v0.2.0
func (q *FakeDelayingQueue) PutWithDelay(value any, delay int64) error
AddAfter 是 FakeDelayingQueue 的方法,它将元素添加到队列,但是并不会延迟 AddAfter is a method of FakeDelayingQueue, it adds an value to the queue, but does not delay
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 是一个用于批量处理任务的结构体 Group is a struct for batch processing tasks
type MessageHandleFunc ¶
定义消息处理函数类型 Define the message handle function type
type Pipeline ¶ added in v0.1.3
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline 是一个结构体,表示管道,用于存储和处理数据 Pipeline is a struct that represents a pipeline, used for storing and processing data
func NewPipeline ¶ added in v0.1.3
func NewPipeline(queue DelayingQueue, conf *Config) *Pipeline
NewPipeline 是一个函数,它创建并返回一个新的 Pipeline NewPipeline is a function, it creates and returns a new Pipeline
func (*Pipeline) GetWorkerNumber ¶ added in v0.1.8
GetWorkerNumber 是 Pipeline 的一个方法,它返回当前正在运行的工作者数量 GetWorkerNumber is a method of Pipeline, it returns the number of workers currently running
func (*Pipeline) Stop ¶ added in v0.1.3
func (pl *Pipeline) Stop()
Stop 是 Pipeline 的一个方法,它用于停止管道 Stop is a method of Pipeline, it is used to stop the pipeline
func (*Pipeline) Submit ¶ added in v0.1.3
Submit 是 Pipeline 的一个方法,它提交一个任务 Submit is a method of Pipeline, it submits a task
func (*Pipeline) SubmitAfter ¶ added in v0.1.4
SubmitAfter 是 Pipeline 的一个方法,它在指定的延迟时间后提交一个任务 SubmitAfter is a method of Pipeline, it submits a task after a specified delay time
func (*Pipeline) SubmitAfterWithFunc ¶ added in v0.1.4
SubmitAfterWithFunc 是 Pipeline 的一个方法,它在指定的延迟时间后提交一个带有自定义处理函数的任务 SubmitAfterWithFunc is a method of Pipeline, it submits a task with a custom processing function after a specified delay time
func (*Pipeline) SubmitWithFunc ¶ added in v0.1.3
func (pl *Pipeline) SubmitWithFunc(fn MessageHandleFunc, msg any) error
SubmitWithFunc 是 Pipeline 的一个方法,它提交一个带有自定义处理函数的任务 SubmitWithFunc is a method of Pipeline, it submits a task with a custom processing function
type Queue ¶
type Queue = interface { // Put 方法用于将元素放入队列。 // The Put method is used to put an element into the queue. Put(value interface{}) error // Get 方法用于从队列中获取元素。 // The Get method is used to get an element from the queue. Get() (value interface{}, err error) // Done 方法用于标记元素处理完成。 // The Done method is used to mark the element as done. Done(value interface{}) // Shutdown 方法用于关闭队列。 // The Shutdown method is used to shut down the queue. Shutdown() // IsClosed 方法用于检查队列是否已关闭。 // The IsClosed method is used to check if the queue is closed. IsClosed() bool }
Queue 接口定义了一个队列应该具备的基本操作。 The Queue interface defines the basic operations that a queue should have.