Commit a993bc13 by Torkel Ödegaard

Merge pull request #2012 from Dieterbe/publish-no-recurse

no unbound recursion in publish()
parents 5896903b e9f38b9f
...@@ -109,25 +109,26 @@ func Setup() error { ...@@ -109,25 +109,26 @@ func Setup() error {
} }
func publish(routingKey string, msgString []byte) { func publish(routingKey string, msgString []byte) {
err := channel.Publish( for {
exchange, //exchange err := channel.Publish(
routingKey, // routing key exchange, //exchange
false, // mandatory routingKey, // routing key
false, // immediate false, // mandatory
amqp.Publishing{ false, // immediate
ContentType: "application/json", amqp.Publishing{
Body: msgString, ContentType: "application/json",
}, Body: msgString,
) },
if err != nil { )
if err == nil {
return
}
// failures are most likely because the connection was lost. // failures are most likely because the connection was lost.
// the connection will be re-established, so just keep // the connection will be re-established, so just keep
// retrying every 2seconds until we successfully publish. // retrying every 2seconds until we successfully publish.
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("publish failed, retrying.") fmt.Println("publish failed, retrying.")
publish(routingKey, msgString)
} }
return
} }
func eventListener(event interface{}) error { func eventListener(event interface{}) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment