Skip to content

Commit

Permalink
Merge pull request #160 from sunmi-OS/feature/imp
Browse files Browse the repository at this point in the history
optimize amqp sdk
  • Loading branch information
luduoxin authored Mar 22, 2024
2 parents 1bbf630 + f6d26c8 commit ff54eda
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mq/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ff54eda

Please sign in to comment.