delayqueue

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 12 Imported by: 2

README

go-delayqueue

基于redis zset 实现延迟队列

  • http服务查看队列详情
消费者
func myJob(msg []interface{}) {
	fmt.Println(msg)
}

func main() {
	delayqueue.Configure(map[string]string{
		"addr":  "localhost:6379",
		"namespace": "myDelay",
	})
	delayqueue.Process("myJob", myJob, 10)
	go delayqueue.StatsServer(8000)
	delayqueue.Run()
}
生产者
func main() {
	delayqueue.Configure(map[string]string{
		"addr":      "localhost:6379",
		"namespace": "myDelay",
	})
	delayqueue.Enqueue("myJob", map[string]string{
		"content": "hello world",
	}, 3*time.Second)
}

Documentation

Index

Constants

View Source
const (
	MaxCount     = 10000
	DefaultCount = 1
	DefaultSleep = 1 * time.Second
)

Variables

View Source
var Config *config

Functions

func Configure

func Configure(options map[string]string)

Configure ...

func Enqueue

func Enqueue(queue string, message interface{}, delayTime time.Duration) (string, error)

Enqueue ...

func GetGoroutineID

func GetGoroutineID() uint64

GetGoroutineID 获取协程ID

func Process

func Process(queue string, delayFunc delayFunc, concurrency int, params ...Params)

Process ...

func Run

func Run()

Run ...

func Stats

func Stats(w http.ResponseWriter, req *http.Request)

func StatsServer

func StatsServer(port int)

Types

type EnqueueData

type EnqueueData struct {
	MsgId   string      `json:"msg_id"`
	Message interface{} `json:"message"`
}

EnqueueData ...

type Params

type Params struct {
	PollSize int64
}

Params ...

Jump to

Keyboard shortcuts

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