diff --git a/mq/rabbitmq/rabbitmq.go b/mq/rabbitmq/rabbitmq.go index e91f8cc..736bc9d 100644 --- a/mq/rabbitmq/rabbitmq.go +++ b/mq/rabbitmq/rabbitmq.go @@ -18,14 +18,18 @@ func connRabbitmq() error { vhost := viper.GetEnvConfig("rabbitmq.vhost").String() user := url.QueryEscape(viper.GetEnvConfig("rabbitmq.user").String()) password := url.QueryEscape(viper.GetEnvConfig("rabbitmq.password").String()) - + scheme := "amqp" + enableTLS := viper.GetEnvConfig("rabbitmq.enableTLS").Bool() + if enableTLS { + scheme = "amqps" + } 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), amqpConfig) + conn, err := amqp.DialConfig(fmt.Sprintf("%s://%s:%s@%s:%s/", scheme, user, password, host, port), amqpConfig) if err != nil { return err }