xmq

package
v0.0.0-...-d6b644b Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package xmq 是为了创建一个统一的队列接口,以便切换队列服务之后可以不改业务代码 只需要修改配置内容和创建部分变量即可

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// 发布消息
	Pub(topic string, payload interface{}) error
	// 延迟发布消息
	Delay(topic string, payload interface{}, delay time.Duration) error
	// 订阅
	Sub(topic, channel string, f HandlerFunc)
	// 创建主题
	CreateTopic(topic string) error
	// 清理网络资源
	Close()
}

Client xobj client

func New

func New(provider Provider, config Config) Client

New 新建存储客户端,为了混用不同的基础施舍,供应商和bucket在调用时填写,不放在设置中。

type Config

type Config struct {
	PubHost string `default:"nsqd"`
	PubTCP  string `default:"4150"`
	PubHTTP string `default:"4151"`
	SubHost string `default:"nsqlookupd"`
	SubTCP  string `default:"4160"`
	SubHTTP string `default:"4161"`
}

Config 配置 兼容各种服务

type Context

type Context interface {
	// Bind binds the payload body into provided type `i`. The default binder
	// is based on json.
	Bind(i interface{}) error
	// Data show the origin payload data body in message
	Data() []byte
	// String convert the origin payload data body to string
	String() string
}

Context 继承了队列接收消息后的上下文,包括消息内容和对消息的一些控制。

type HandlerFunc

type HandlerFunc func(c Context) error

HandlerFunc 订阅者处理消息的函数

type LogrusLogger

type LogrusLogger struct{}

LogrusLogger is an adaptor between the weird go-nsq Logger and our standard logrus logger.

func NewLogrusLogger

func NewLogrusLogger() (logger LogrusLogger, level nsq.LogLevel)

NewLogrusLogger returns a new LogrusLogger and the current log level. This is a format to easily plug into nsq.SetLogger.

func NewLogrusLoggerAtLevel

func NewLogrusLoggerAtLevel(l logrus.Level) (logger LogrusLogger, level nsq.LogLevel)

NewLogrusLoggerAtLevel returns a new LogrusLogger with the provided log level mapped to nsq.LogLevel for easily plugging into nsq.SetLogger.

func (LogrusLogger) Output

func (n LogrusLogger) Output(_ int, s string) error

Output implements stdlib log.Logger.Output using logrus Decodes the go-nsq log messages to figure out the log level

type Provider

type Provider int

Provider 服务提供商

const (
	ProviderNSQ Provider = iota
)

all providers

Jump to

Keyboard shortcuts

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