func Publish(name string, body []byte) {
channel, err := connection.Channel()
defer channel.Close() // commenting out this does not cause any errors but too many channels are left.
err := channel.Publish("", name, false, false, amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: body,
})
util.HandlerError(err, "Could not publish message for mq : "+name)
}
I am publishing messages to rabbitMQ at a small rate (30/s). If I close the connection after the message publishes, it is giving me the below error.
My code: