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
-
Starting a new process
Don't start the process
-
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'"