amqp

package
v0.0.0-...-5a15951 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AMQP_API           = utils.Getenv("AMQP_API", "amqp://guest:guest@localhost:5672/")
	AMQP_NAME_QUEUE    = utils.Getenv("AMQP_NAME_QUEUE", "benchmark")
	AMQP_BINDING_KEY   = utils.Getenv("AMQP_BINDING_KEY", "")
	AMQP_CONSUMER_TAG  = utils.Getenv("AMQP_CONSUMER_TAG", "")
	AMQP_EXCHANGE_LIST = utils.Getenv("AMQP_EXCHANGE_LIST", "benchmark")
	AMQP_EXCHANGE_TYPE = utils.Getenv("AMQP_EXCHANGE_TYPE", "headers")

	CONSUMER = &Consumer{}
)

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	Conn *amqp.Connection

	QueueName string
	// contains filtered or unexported fields
}

Consumer holds all information about the RabbitMQ connection This setup does limit a consumer to one exchange. This should not be an issue. Having to connect to multiple exchanges means something else is structured improperly.

func Listen

func Listen() Consumer

func NewConsumer

func NewConsumer(uri, changes, exchangeType, queueName, bindingKey, consumerTag string) *Consumer

func (*Consumer) AnnounceQueue

func (c *Consumer) AnnounceQueue() (<-chan amqp.Delivery, error)

AnnounceQueue sets the queue that will be listened to for this connection...

func (*Consumer) Connect

func (c *Consumer) Connect() error

func (*Consumer) Handle

func (c *Consumer) Handle(
	deliveries <-chan amqp.Delivery,
	fn func(<-chan amqp.Delivery),
	queue string)

Handle has all the logic to make sure your program keeps running d should be a delievey channel as created when you call AnnounceQueue fn should be a function that handles the processing of deliveries this should be the last thing called in main as code under it will become unreachable unless put int a goroutine. The q and rk params are redundant but allow you to have multiple queue listeners in main without them you would be tied into only using one queue per connection

func (*Consumer) Publish

func (c *Consumer) Publish(message []byte) error

func (*Consumer) ReConnect

func (c *Consumer) ReConnect(queueName string) (<-chan amqp.Delivery, error)

ReConnect is called in places where NotifyClose() channel is called wait 30 seconds before trying to reconnect. Any shorter amount of time will likely destroy the error log while waiting for servers to come back online. This requires two parameters which is just to satisfy the AccounceQueue call and allows greater flexability

func (*Consumer) Shutdown

func (c *Consumer) Shutdown() error

Jump to

Keyboard shortcuts

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