async

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTaskConsumer

func NewTaskConsumer(ctx context.Context, opts ...func(*ConsumerOption)) *taskConsumer

Types

type Channel

type Channel interface {
	Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error
	Consume(queue, consumer string, autoAck, exclusive, noLocal, noWail bool, args amqp.Table) (<-chan amqp.Delivery, error)
	Close() error
}

Channel is a channel interface to make testing possible. It is highly recommended to use *amqp.Channel as the interface implementation.

func NewRabbitmqChannel

func NewRabbitmqChannel(opts ...mq.Option) (Channel, error)

type ConsumerOption

type ConsumerOption struct {
	Pool        *routine.Pool   // goroutine safe run pool
	Manager     ManagerExecutor // manager executor how to run
	Marshal     mq.MarshalAPI   // mq  assemble request or response
	JSONHandler jsoniter.API
	ParamPool   ParamPool // get Param
	Validator   validator.Validator
}

type Executor

type Executor interface {
	SafeCopy() Executor
	ID() string
	Run(ctx context.Context, data []byte) error
}

Executor your business should implement it

type ManagerExecutor

type ManagerExecutor interface {
	Register(executors ...Executor) error
	Run(ctx context.Context, param *Param) error
}

func NewManager

func NewManager() ManagerExecutor

type Param

type Param struct {
	Name     string                 `json:"name" binding:"required"`
	Metadata map[string]interface{} `json:"metadata"`
	Data     []byte                 `json:"data"`
}

type ParamPool

type ParamPool interface {
	Get() *Param
	Put(*Param)
}

func NewParamPool

func NewParamPool() ParamPool

type ProducerOption

type ProducerOption struct {
	Marshal     mq.MarshalAPI
	Exchange    string
	JSONHandler jsoniter.API
	ParamPool   ParamPool
	Validator   validator.Validator
}

type TaskProducer

type TaskProducer struct {
	ProducerOption
	// contains filtered or unexported fields
}

func NewTaskProducer

func NewTaskProducer(opts ...func(*ProducerOption)) *TaskProducer

NewProducer return message.Publisher

func (*TaskProducer) Close

func (t *TaskProducer) Close() error

func (*TaskProducer) GetParam

func (t *TaskProducer) GetParam() *Param

func (*TaskProducer) Publish

func (t *TaskProducer) Publish(ctx context.Context, channel Channel, routingKey string, param *Param) error

Jump to

Keyboard shortcuts

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