|
@@ -109,25 +109,26 @@ func Setup() error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func publish(routingKey string, msgString []byte) {
|
|
func publish(routingKey string, msgString []byte) {
|
|
|
- err := channel.Publish(
|
|
|
|
|
- exchange, //exchange
|
|
|
|
|
- routingKey, // routing key
|
|
|
|
|
- false, // mandatory
|
|
|
|
|
- false, // immediate
|
|
|
|
|
- amqp.Publishing{
|
|
|
|
|
- ContentType: "application/json",
|
|
|
|
|
- Body: msgString,
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if err != nil {
|
|
|
|
|
|
|
+ for {
|
|
|
|
|
+ err := channel.Publish(
|
|
|
|
|
+ exchange, //exchange
|
|
|
|
|
+ routingKey, // routing key
|
|
|
|
|
+ false, // mandatory
|
|
|
|
|
+ false, // immediate
|
|
|
|
|
+ amqp.Publishing{
|
|
|
|
|
+ ContentType: "application/json",
|
|
|
|
|
+ Body: msgString,
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+ 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 {
|