streadway / amqp

Go client for AMQP 0.9.1
http://godoc.org/github.com/streadway/amqp
BSD 2-Clause "Simplified" License
4.88k stars 621 forks source link

Publishing to an exchange that does not exist #449

Closed rebbuh closed 4 years ago

rebbuh commented 4 years ago

When a message is published to an exchange that does not exist, the Publish method does not return an error. Is there any way to handle this situation?

I know that I can use NotifyReturn to get a Return struct when the mandatory flag is set and there is no route for the given routing key, but obviously this does not apply to non-existing exchanges.

This somehow relates to issue #445, but it was closed by @BentCoder shortly after its creation without any comment.

bentcoder commented 4 years ago

http://www.inanzzz.com/index.php/post/0aeg/creating-a-rabbitmq-producer-example-with-golang

There is a "confirmation mode" section in post above. It addresses your issue. The "create.go" file uses it. Also read the whole post. It explains many things.

rebbuh commented 4 years ago

Thanks! The important part is to also subscribe to channel.NotifyClose, not only to connection.NotifyClose.