From faac75e634544ab318e008e06f6b742b3c788260 Mon Sep 17 00:00:00 2001 From: luduoxin <379356950@qq.com> Date: Fri, 22 Mar 2024 16:05:55 +0800 Subject: [PATCH 1/2] Optimize amqp sdk --- rabbitmq/rabbitmq.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rabbitmq/rabbitmq.go b/rabbitmq/rabbitmq.go index 1a8c127f..eef12ea8 100644 --- a/rabbitmq/rabbitmq.go +++ b/rabbitmq/rabbitmq.go @@ -18,6 +18,11 @@ 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{ Vhost: vhost, @@ -25,7 +30,7 @@ func connRbbitmq() error { 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), amqpcoinf) if err != nil { return err } From 86dfa86d359dba30e9a862f3aa3749d62d0b7d44 Mon Sep 17 00:00:00 2001 From: luduoxin <379356950@qq.com> Date: Fri, 22 Mar 2024 16:15:44 +0800 Subject: [PATCH 2/2] Optimize amqp sdk --- rabbitmq/rabbitmq.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rabbitmq/rabbitmq.go b/rabbitmq/rabbitmq.go index eef12ea8..a49672f7 100644 --- a/rabbitmq/rabbitmq.go +++ b/rabbitmq/rabbitmq.go @@ -24,13 +24,13 @@ func connRbbitmq() error { scheme = "amqps" } - amqpcoinf := amqp.Config{ + amqpConfig := amqp.Config{ Vhost: vhost, Heartbeat: 10 * time.Second, Locale: "en_US", } - conn, err := amqp.DialConfig(fmt.Sprintf("%s://%s:%s@%s:%s/", scheme, 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 }