amqp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

README

amqp

amqp Go RabbitMQ AMQP 0.9.1 Client Library .

primary module

go get github.com/xyqweb/amqp

Limitation

golang version >= 1.18

Usage

See the _examples

License

BSD 3-Clause License- see LICENSE for more details..

Documentation

Index

Constants

View Source
const (
	VERSION                    = "1.0.1"
	AttemptName                = "amqp-attempt"
	DefaultExchange            = "exchange"
	NotFoundIndex              = -1
	DefaultAttempt       int32 = 1  // default exec times
	ErrDelay                   = 60 // default exec queue fail push delay time,unit second
	DeadLetterExchange         = "x-dead-letter-exchange"
	DeadLetterRoutingKey       = "x-dead-letter-routing-key"
	DelayKey                   = "amqp-delay"
	TtrKey                     = "amqp-ttr"
)

Variables

View Source
var (
	Config         *config
	RabbitmqConfig = rabbitmqConfig{}
)
View Source
var Consumer = consumer{/* contains filtered or unexported fields */}
View Source
var Producer = producer{/* contains filtered or unexported fields */}
View Source
var Util = util{}

Functions

func HeartBeater

func HeartBeater(interval time.Duration, job func())

HeartBeater is a convenience function for add singleton mode job.

Types

type ConsumerHandler

type ConsumerHandler func(ctx context.Context, data *QueueData) error

type ExpireFunc

type ExpireFunc func(interface{})

ExpireFunc Destruction function for object.

type NewFunc

type NewFunc func() (interface{}, error)

NewFunc Creation function for object.

type Pool

type Pool struct {
	TTL     time.Duration               // Time To Live for pool items.
	NewFunc func() (interface{}, error) // Callback function to create pool item.
	// ExpireFunc is the for expired items destruction.
	// This function needs to be defined when the pool items
	// need to perform additional destruction operations.
	// Eg: net.Conn, os.File, etc.
	ExpireFunc func(interface{})
	// contains filtered or unexported fields
}

func NewPool

func NewPool(ttl time.Duration, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool

NewPool creates and returns a new object pool. To ensure execution efficiency, the expiration time cannot be modified once it is set.

Note the expiration logic: ttl = 0 : not expired; ttl < 0 : immediate expired after use; ttl > 0 : timeout expired;

func (*Pool) Clear

func (p *Pool) Clear()

Clear clears pool, which means it will remove all items from pool.

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool. If `p` has ExpireFunc, then it automatically closes all items using this function before it's closed. Commonly you do not need to call this function manually.

func (*Pool) Get

func (p *Pool) Get() (interface{}, error)

Get picks and returns an item from pool. If the pool is empty and NewFunc is defined, it creates and returns one from NewFunc.

func (*Pool) Put

func (p *Pool) Put(value interface{}) error

Put puts an item to pool.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the count of available items of pool.

func (*Pool) TimestampMilli

func (p *Pool) TimestampMilli() int64

TimestampMilli returns the timestamp in milliseconds.

type Queue

type Queue struct {
	QueueName string      `json:"queue_name"`
	Type      string      `json:"type"`
	Data      interface{} `json:"data"` // Data和Body只需要传一个,Body的级别比Data更高
	Delay     int         `json:"delay"`
	Ttr       int         `json:"ttr"`
}

type QueueData

type QueueData struct {
	MessageId string      `json:"messageId"`
	Headers   amqp.Table  `json:"headers"`
	QueueName string      `json:"queue_name"`
	Type      string      `json:"type"`
	Data      interface{} `json:"data"`
	Ttr       int         `json:"ttr"`
}

QueueData 队列内容

Jump to

Keyboard shortcuts

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