xnsq

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

Documentation

Overview

NSQ队列消息 此模块依赖xlog模块,所以使用时请注意使用 `xlog.Regedit()` 来注册日志配置

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNsq added in v0.0.19

func AddNsq(rou string, fun NsqFunc) error

添加NSQ队列监听任务

rou	队列下标标识
fun	队列处理函数

func Listen

func Listen()

NSQ队列监听 导出函数,需要在入口处进行执行 `go xnsq.Listen()` 来进行同步监听

func Regedit

func Regedit(c *Config)

注入配置项

func Router

func Router(router string, fun NsqFunc) error

注册NSQ路由信息 如果路由中已存在,则会返回错误信息

router	注册路由
fun		执行的函数

func Set

func Set(funs string, param any) error

写入队列【若未开启队列的话,将不管队列方法执行的结果,即程序会运行0~1次,即使是失败,所以建议开启NSQ队列,用以保证任务能成功执行】

fun		写入的服务名称,对应读取时的名称配置
param	传入的参数,对应读取时的参数结构

func SetDef

func SetDef(fun string, param any, t time.Duration) error

写入延时队列

fun		写入的服务名称,对应读取时的名称配置
param	传入的参数,对应读取时的参数结构
t		延时时间【目前配置禁止超过1小时的延时任务,若某程序需要延迟1天的话请使用30min进行循环写入的形式来进行实现】

Types

type Config

type Config struct {
	Set            string // 写入队列的nsqd服务域名端口,一般为127.0.0.1:4150
	SetTopic       string // 写入队列的topic名称
	Get            string // 读取队列的nsqlookupd域名端口,一般为127.0.0.1:4161,空表示不监听此服务
	GetTopic       string // 读取队列的get_topic服务
	GetChannel     string // 读取队列的get_channel服务
	GetMaxInFlight int    // 最大并发消费数配置,建议配置为nsqd服务的倍数,默认为1
	MaxAttempts    uint16 // 错误最大重试次数
}

type NSQ

type NSQ struct {
	Func    string `json:"func"`     // 调用方法
	Time    string `json:"time"`     // 发送时间
	Param   any    `json:"param"`    // 传入参数
	RunTime string `json:"run_time"` // 期望运行时间,若此值不为空则表示再次延时
}

NSQ的message消息结构,用于json解构及参数传递

type NsqFunc

type NsqFunc func(param []byte) error

Jump to

Keyboard shortcuts

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