worker

package module
v0.0.0-...-7ed8d67 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 4 Imported by: 1

README

amqp-retry-worker Go Report Card GoDoc

out of box amqp retry worker for golang

License

MIT © zcong1993

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff interface {
	// GetDelay get retry delay timeout(ms) by payload
	// get identity from msg payload yourself
	GetDelay(payload []byte, routerKey string) string
	// Reset reset retry delay timeout, be called when work retry success or hit max retry
	// can do some gc here
	Reset(payload []byte, routerKey string)
}

Backoff control the work retry delay time

type DefaultBackoff

type DefaultBackoff struct {
	// contains filtered or unexported fields
}

DefaultBackoff always return base

func NewDefaultBackoff

func NewDefaultBackoff(base int) *DefaultBackoff

NewDefaultBackoff return a new DefaultBackoff instance

func (*DefaultBackoff) GetDelay

func (db *DefaultBackoff) GetDelay(payload []byte, routerKey string) string

GetDelay impl Backoff GetDelay

func (*DefaultBackoff) Reset

func (db *DefaultBackoff) Reset(payload []byte, routerKey string)

Reset impl Backoff Reset

type RetryWorker

type RetryWorker struct {
	ExchangeName  string
	QueueName     string
	WithDeadQueue bool
	// contains filtered or unexported fields
}

RetryWorker is our retry worker struct

func NewRetryWorker

func NewRetryWorker(url string, exchangeName, queueName string, routerKeys []string, worker Worker, backoff Backoff, maxRetry int, withDeadQueue bool) *RetryWorker

NewRetryWorker return a new RetryWorker instance

func (*RetryWorker) Run

func (rw *RetryWorker) Run()

Run start worker

type Worker

type Worker interface {
	// Do do the worker logic, return two args, first is err, second is if should retry
	// if err is nil, means work success, retry is optional
	// when err is not nil, if retry will copy msg to delay queue, if not, will handle msg with nack and not requeue
	Do(payload []byte, routerKey string) (err error, retry bool)
}

Worker is worker interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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