sneaker

package module
v3.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 8 Imported by: 4

README

SneakerWorker for Golang

Dependencies 依赖
  • RabbitMQ
Usage 使用方法

1.在你的项目中的config目录下创建以下两个文件

amqp.yml
workers.yml

This is a example.

2.workers

example 示例

3.main

example 示例

workers.yml配置说明
---
- name: TreatWorker  # worker的名称
  exchange: sneaker.example.default  # 消息经过的Exchange
  routing_key: sneaker.example.treat  # 消息经过的routing_key
  queue: sneaker.example.treat  # 消息进入的queue
  durable: true
  log: logs/treatWorker.log # 自定义日志文件
  threads: 1  # 并发处理数量
  steps:  # 重试队列的延时配置
    - 5000       # 5 Second
    - 30000      # 30 Second
    - 60000      # 1 Minute

Documentation

Index

Constants

View Source
const (
	DefaultLog = "logs/workers.log"
)

Variables

This section is empty.

Functions

func SubscribeMessageByQueue

func SubscribeMessageByQueue(worker WorkerI, arguments amqp.Table) (err error)

func SubscribeMessages added in v3.1.9

func SubscribeMessages(worker WorkerI, arguments amqp.Table) (err error)

Types

type Exception

type Exception struct {
	Msg string
}

type RabbitMqConnect

type RabbitMqConnect struct {
	*amqp.Connection
}

func (*RabbitMqConnect) DeclareExchange

func (conn *RabbitMqConnect) DeclareExchange(name, kind string, durable, autoDelete, internal, noWait bool, arguments amqp.Table) error

func (*RabbitMqConnect) DeclareQueue

func (conn *RabbitMqConnect) DeclareQueue(queueName string, durable, autoDelete, internal, noWait bool, arguments amqp.Table) error

func (*RabbitMqConnect) PublishMessageToQueue

func (conn *RabbitMqConnect) PublishMessageToQueue(queue, contentType string, mandatory, immediate bool, message *[]byte, arguments amqp.Table, deliveryMode uint8, expiration string) error

func (*RabbitMqConnect) PublishMessageWithRouteKey

func (conn *RabbitMqConnect) PublishMessageWithRouteKey(exchange, routeKey, contentType string, mandatory, immediate bool, message *[]byte, arguments amqp.Table, deliveryMode uint8, expiration string) error

func (*RabbitMqConnect) QueueBind

func (conn *RabbitMqConnect) QueueBind(name, key, exchange string, noWait bool, arguments amqp.Table) error

type Worker

type Worker struct {
	Name         string            `yaml:"name"`
	Exchange     string            `yaml:"exchange"`
	ExchangeType string            `yaml:"exchange_type"`
	RoutingKey   string            `yaml:"routing_key"`
	Queue        string            `yaml:"queue"`
	Log          string            `yaml:"log"`
	Durable      bool              `yaml:"durable"`
	Options      map[string]string `yaml:"options"`
	Arguments    map[string]string `yaml:"arguments"`
	Threads      int               `yaml:"threads"`

	Ready  bool
	Logger *log.Logger
	// contains filtered or unexported fields
}

func (*Worker) GetArguments

func (worker *Worker) GetArguments() map[string]string

func (*Worker) GetChannel added in v3.0.11

func (worker *Worker) GetChannel() *amqp.Channel

func (*Worker) GetDelayQueue added in v3.0.2

func (worker *Worker) GetDelayQueue() string

func (*Worker) GetDurable

func (worker *Worker) GetDurable() bool

func (*Worker) GetExchange

func (worker *Worker) GetExchange() string

func (*Worker) GetExchangeType

func (worker *Worker) GetExchangeType() string

func (*Worker) GetFailedQueue

func (worker *Worker) GetFailedQueue() string

func (*Worker) GetLog

func (worker *Worker) GetLog() string

func (*Worker) GetLogFolder

func (worker *Worker) GetLogFolder() string

func (*Worker) GetName

func (worker *Worker) GetName() string

func (*Worker) GetOptions

func (worker *Worker) GetOptions() map[string]string

func (*Worker) GetQueue

func (worker *Worker) GetQueue() string

func (*Worker) GetRabbitMqConnect added in v3.0.4

func (worker *Worker) GetRabbitMqConnect() *RabbitMqConnect

func (*Worker) GetRetryQueue

func (worker *Worker) GetRetryQueue() string

func (*Worker) GetRoutingKey

func (worker *Worker) GetRoutingKey() string

func (*Worker) GetThreads

func (worker *Worker) GetThreads() int

func (*Worker) InitLogger

func (worker *Worker) InitLogger()

func (*Worker) IsChannelClosed added in v3.1.0

func (worker *Worker) IsChannelClosed() bool

func (*Worker) IsReady added in v3.0.4

func (worker *Worker) IsReady() bool

func (*Worker) LogDebug

func (worker *Worker) LogDebug(text ...interface{})

func (*Worker) LogError

func (worker *Worker) LogError(text ...interface{})

func (*Worker) LogInfo

func (worker *Worker) LogInfo(text ...interface{})

func (*Worker) Perform added in v3.0.3

func (worker *Worker) Perform(message interface{})

func (*Worker) Recycle added in v3.0.5

func (worker *Worker) Recycle()

func (*Worker) Retry added in v3.1.6

func (worker *Worker) Retry(d *amqp.Delivery) (err error)

func (*Worker) SetChannel added in v3.0.11

func (worker *Worker) SetChannel(channel *amqp.Channel)

func (*Worker) SetRabbitMqConnect added in v3.0.3

func (worker *Worker) SetRabbitMqConnect(rabbitMqConnect *RabbitMqConnect)

func (*Worker) Start added in v3.0.4

func (worker *Worker) Start()

func (*Worker) Stop added in v3.0.4

func (worker *Worker) Stop()

func (*Worker) Work

func (worker *Worker) Work(body *[]byte) (err error)

type WorkerI

type WorkerI interface {
	Work(*[]byte) error
	GetName() string
	GetExchange() string
	GetExchangeType() string
	GetRoutingKey() string
	GetQueue() string
	GetDelayQueue() string
	GetRetryQueue() string
	GetFailedQueue() string
	GetLog() string
	GetLogFolder() string
	GetDurable() bool
	GetOptions() map[string]string
	GetArguments() map[string]string
	GetThreads() int
	GetRabbitMqConnect() *RabbitMqConnect
	SetRabbitMqConnect(*RabbitMqConnect)
	GetChannel() *amqp.Channel
	SetChannel(channel *amqp.Channel)

	InitLogger()
	Perform(interface{})
	Retry(d *amqp.Delivery) (err error)

	IsChannelClosed() bool
	IsReady() bool
	Start()
	Stop()
	Recycle()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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