In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to achieve Golang rabbitMQ producers and consumers. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Consumer package mainimport ("fmt"github.com/streadway/amqp") func failOnError (err error, msg string) {if err! = nil {fmt.Println ("% s:% s", msg, err)}} / / can only operate func main () {conn on the server where rabbitmq is installed. Err: = amqp.Dial ("amqp://mquser:123456@127.0.0.1/toutiao") failOnError (err, "Failed to connect to RabbitMQ") defer conn.Close () ch, err: = conn.Channel () failOnError (err, "Failed to open a channel") defer ch.Close () Q, err: = ch.QueueDeclare ("toutiao.web.test") / / queue name false, / / durable false, / / delete when unused false, / / exclusive false, / / no-wait nil, / / arguments) failOnError (err, "Failed to declare a queue") msgs, err: = ch.Consume (q.Name) / / queue "toutiao", / / consumer true, / / auto-ack,true disappear after consumption false, / / exclusive false, / / no-local false, / / no-wait nil, / / args) failOnError (err) "Failed to register a consumer") forever: = make (chan bool) go func () {for d: = range msgs {fmt.Println (fmt.Sprintf ("returned message:% s", d.Body))} () fmt.Println ("[*] Waiting for messages. To exit press CTRL+C ")
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.