go_delay_queue

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-delay-queue

WIKI

https://github.com/wsqun/go-delay-queue/wiki/Introduction

Installation

make sure to initialize a Go module before installing go-delay-queue:

go get https://github.com/wsqun/go-delay-queue

Import

import "github.com/wsqun/go-delay-queue"

QuickStart

demo操作

kafka可使用docker搭建

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelayLevel

type DelayLevel struct {
	TopicName string                    //队列名
	Level     int                       // 延迟等级
	RetryNums int                       // 重试次数
	NoAlive   bool                      // 当为true 不获取延迟消息
	Ttl       time.Duration             // 延迟时间
	DealFn    func(DelayTopicMsg) error // 处理方法
}

延迟等级定义

type DelayServeConf

type DelayServeConf struct {
	ClientCtx   context.Context
	ClientWg    *sync.WaitGroup
	DelayLevels []*DelayLevel
	Debug       bool
}

配置

type DelayTopicMsg

type DelayTopicMsg struct {
	Id        uint64      `json:"id" from:"id"`
	Level     int         `json:"level" from:"level"`           // 延迟等级
	ExpiredAt int64       `json:"expired_at" from:"expired_at"` // 生效时间
	RetryNums int         `json:"retry_nums" from:"retry_nums"` // 重试次数
	DelayMsg  interface{} `json:"delay_msg" from:"delay_msg"`   // 延迟消息
}

队列延迟消息

type Delayer

type Delayer struct {
	Debug bool
	// contains filtered or unexported fields
}

func NewDelay

func NewDelay(conf *DelayServeConf, queuer Iqueue, opt ...OptFn) (dr *Delayer, err error)

func (*Delayer) AddMsg

func (dr *Delayer) AddMsg(level int, msg interface{}) (err error)

添加延迟消息

func (*Delayer) Run

func (dr *Delayer) Run()

func (*Delayer) SetDurationMin added in v1.0.2

func (dr *Delayer) SetDurationMin(ttl time.Duration)

调整最小延迟时间

type Iqueue

type Iqueue interface {
	// 订阅消息
	// topic 为队列名,dealFn为消息处理逻辑方法,[]byte为队列消息,当err发生则放回消息,默认为程序退出
	SubscribeMsg(topic string, dealFn func([]byte) (err error)) (err error)
	// 生产消息
	PublishMsg(topic string, msg []byte) (err error)
}

type OptFn added in v1.0.2

type OptFn func(dr *Delayer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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