delayqueue

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 13 Imported by: 2

README

go-delayqueue

基于redis zset 实现延迟队列

  • http服务查看队列详情
  • 集群支持
  • 支持批量消费消息 TODO
  • 重试机制
  • ACK确认机制 TODO
消费者
func myJob(msg interface{}) {
	fmt.Println(msg)
    // 业务重试
    delayqueue.RetryEnqueue("myJob", msg)
}

func main() {
    go delayqueue.StatsServer(8000)

	delayqueue.Configure(map[string]string{
		"addr":  "localhost:6379",
		"namespace": "myDelay",
	})
	delayqueue.Process("myJob", myJob, 10)
	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 (
	RetryNum      = 2 // 最大重试次数
	RetryInterval = 1 // 重试时间间隔(秒)
)
View Source
const (
	MaxCount     = 10000
	DefaultCount = 1
	DefaultSleep = 1 * time.Second
)

Variables

This section is empty.

Functions

func Enqueue

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

Enqueue ...

func GetGoroutineID

func GetGoroutineID() uint64

GetGoroutineID 获取协程ID

func InitClient added in v0.0.2

func InitClient(opt *redis.Options)

InitClient ...

func InitClusterClient added in v0.0.2

func InitClusterClient(opt *redis.ClusterOptions)

InitClusterClient ...

func Process

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

Process ...

func RetryEnqueue added in v0.0.2

func RetryEnqueue(queue string, member interface{}) (string, error)

RetryEnqueue ...

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"`
	RetryNum      uint64      `json:"retry_num"`      // 最大重试次数
	RetryInterval int64       `json:"retry_interval"` // 重试时间间隔(秒)
}

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