queue

package module
v0.0.0-...-930e6a6 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

QUEUE

License Go Report Card GoDoc Build Status

摘要

queue 是一个基于 mpsc 的异步队列,屏蔽业务逻辑与队列的耦合

Feature

  • 提供多生产者、单消费者的消息推送
  • 提供立即关闭、业务完成关闭两种方式
  • 重复关闭无异常

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MPSC

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

MPSC 基于 go 的multi-produce single-consumer的数据结构

func NewMpsc

func NewMpsc() *MPSC

func (*MPSC) Empty

func (mpsc *MPSC) Empty() bool

Empty 清空队列

func (*MPSC) Pop

func (mpsc *MPSC) Pop() interface{}

Pop 从队列中提取一条消息交付给消费者

func (*MPSC) Push

func (mpsc *MPSC) Push(x interface{})

Push 添加一条新的消息到队列的末尾

type PosionPill

type PosionPill struct{}

PosionPill 退出指令定义,用于当前任务队列数据处理完成时退出

type Queue

type Queue interface {
	Push(interface{})
	StopGraceful()
	Stop()
}

异步队列的定义,允许执行消息推送、停止直至消息处理完成、立即停止三种操作

func BoundedQueueCSP

func BoundedQueueCSP(size int, invoker ReceiveFunc) Queue

BoundedQueueCSP 创建一个指定缓冲区大小的队列

func BoundedQueueMpsc

func BoundedQueueMpsc(size int, receiver ReceiveFunc) Queue

BoundedQueueMpsc 创建一个指定缓冲区大小的队列

type QueueManager

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

QueueManager 队列管理器

func (*QueueManager) GetOrCreateQueue

func (cm *QueueManager) GetOrCreateQueue(key interface{}, receive ReceiveFunc) (newQueue Queue, newer bool)

GetOrCreateQueue 创建通道以供使用

func (*QueueManager) New

func (cm *QueueManager) New() *QueueManager

New 创建新的队列管理器实例

func (*QueueManager) Push

func (cm *QueueManager) Push(key interface{}, msg interface{}) (sended bool)

Push 向指定的异步队列推送消息,当队列不存在是,返回 false

func (*QueueManager) Release

func (cm *QueueManager) Release(key interface{})

Release 释放管理器中指定的队列

func (*QueueManager) ReleaseAll

func (cm *QueueManager) ReleaseAll()

ReleaseAll 释放管理器中所有的异步队列

type ReceiveFunc

type ReceiveFunc = func(any interface{})

Jump to

Keyboard shortcuts

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