amqp

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

AMQP

Producer

Usage
// AMQP Producer - Initialize and connect
producer, err := amqp.NewProducer(*uri, *exchange, *exchangeType)
if err != nil {
  log.Printf("%s", err)
}
// AMQP Producer - Close connection
defer producer.Shutdown()

producer.Publish(*exchange, *exchangeType, routing_key, body, headers, false)

Consumer

Usage
// AMQP Consumer - Initialize and connect
consumer, err := amqp.NewConsumer(*uri, *exchange, *exchangeType, *queue, *consumerTag,<array of bindingKey strings>)
if err != nil {
  log.Printf("%s", err)
}
// AMQP Consumer - Close connection
defer consumer.Shutdown()

// Consume messages
msgs, _ := consumer.Consume(*queue)

Guidelines

When RabbitMQ goes down
  1. Starting a new process Don't start the process

  2. Existing process

Close the existing connection and shutdown the process. Try reconnecting to RabbitMQ for configurable x times.

closing: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"

Documentation

Index

Constants

View Source
const (
	ExchangeTopic string = amqp.ExchangeTopic
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

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

func NewConsumer

func NewConsumer(amqpURI, exchange, exchangeType, queueName, ctag string, keys []string) (*Consumer, error)

func (*Consumer) Consume

func (consumer *Consumer) Consume(queue_name string) (<-chan amqp.Delivery, error)

func (*Consumer) Shutdown

func (consumer *Consumer) Shutdown() error

type Producer

type Producer struct {
	// contains filtered or unexported fields
}
var (
	ProducerClient *Producer
)

func NewProducer

func NewProducer(amqpURI, exchange, exchangeType string) (*Producer, error)

func (*Producer) Publish

func (producer *Producer) Publish(exchange, exchangeType, routingKey, body string, headers amqp.Table, reliable bool) error

func (*Producer) Shutdown

func (producer *Producer) Shutdown() error

Jump to

Keyboard shortcuts

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