diff --git a/rabbitmq/rabbitmq.go b/rabbitmq/rabbitmq.go index 1a8c127f..a49672f7 100644 --- a/rabbitmq/rabbitmq.go +++ b/rabbitmq/rabbitmq.go @@ -18,14 +18,19 @@ func connRbbitmq() error { vhost := viper.GetEnvConfig("rabbitmq.vhost") user := url.QueryEscape(viper.GetEnvConfig("rabbitmq.user")) password := url.QueryEscape(viper.GetEnvConfig("rabbitmq.password")) + scheme := "amqp" + enableTLS := viper.GetEnvConfigBool("rabbitmq.enableTLS") + if enableTLS { + scheme = "amqps" + } - amqpcoinf := amqp.Config{ + amqpConfig := amqp.Config{ Vhost: vhost, Heartbeat: 10 * time.Second, Locale: "en_US", } - conn, err := amqp.DialConfig(fmt.Sprintf("amqp://%s:%s@%s:%s/", user, password, host, port), amqpcoinf) + conn, err := amqp.DialConfig(fmt.Sprintf("%s://%s:%s@%s:%s/", scheme, user, password, host, port), amqpConfig) if err != nil { return err }