service

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GeniricQueue = NewMemoryQueue[any]("geniricQueue", 100, 1)
View Source
var IntQueue = NewMemoryQueue[any]("intQueue", 100, 1)
View Source
var StringQueue = NewMemoryQueue[any]("stringQueue", 100, 1)

Functions

This section is empty.

Types

type IQueue

type IQueue[T any] interface {
	// SetStatus 设置队列运行状态
	SetConsumerRunning(status bool) bool
	// Status 返回队列全部状态
	GetStatus() interface{}
	// 根据key查询对应的值
	GetConsumerRunning() bool
	// SetStatus 设置队列运行状态
	SetConsumerCount(count int) int
	// Enqueue 将项目放入队列
	Enqueue(ctx context.Context, item T) error
	// Dequeue 从队列中取出项目
	Dequeue(ctx context.Context) (T, error)
	// 启动消费者
	RunConsume(ctx context.Context, message_processor func(T))

	// Close 关闭队列
	Close()
	// WaitUntilEmpty 等待队列为空
	WaitUntilEmpty()
}

func GetQueueByName

func GetQueueByName(name string) IQueue[any]

func GetQueues

func GetQueues() []IQueue[any]

type MemoryQueue

type MemoryQueue[T any] struct {
	Name            string // 队列的名称
	Capacity        int
	ConsumerRunning bool
	ConsumerCount   int
	ConsumeSpeed    int
	// contains filtered or unexported fields
}

func NewMemoryQueue

func NewMemoryQueue[T any](name string, capacity int, consumeSpeed int) *MemoryQueue[T]

func (*MemoryQueue[T]) Close

func (q *MemoryQueue[T]) Close()

func (*MemoryQueue[T]) Dequeue

func (q *MemoryQueue[T]) Dequeue(ctx context.Context) (T, error)

Dequeue 从队列中取出一个项目

func (*MemoryQueue[T]) Enqueue

func (q *MemoryQueue[T]) Enqueue(ctx context.Context, item T) error

func (*MemoryQueue[T]) GetConsumerCount

func (q *MemoryQueue[T]) GetConsumerCount() int

func (*MemoryQueue[T]) GetConsumerRunning

func (q *MemoryQueue[T]) GetConsumerRunning() bool

func (*MemoryQueue[T]) GetStatus

func (q *MemoryQueue[T]) GetStatus() interface{}

func (*MemoryQueue[T]) RunConsume

func (q *MemoryQueue[T]) RunConsume(ctx context.Context, message_processor func(T))

func (*MemoryQueue[T]) SetConsumerCount

func (q *MemoryQueue[T]) SetConsumerCount(count int) int

func (*MemoryQueue[T]) SetConsumerRunning

func (q *MemoryQueue[T]) SetConsumerRunning(status bool) bool

func (*MemoryQueue[T]) WaitUntilEmpty

func (q *MemoryQueue[T]) WaitUntilEmpty()

Jump to

Keyboard shortcuts

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