当前位置: 首页 > news >正文

电商导购网站怎么做广州seo代理计费

电商导购网站怎么做,广州seo代理计费,扬州做网站的公司,潍坊企业自助建站系统1.发布订阅 在Fanout模式中,一条消息,会被所有订阅的队列都消费。但是,在某些场景下,我们希望不同的消息被不同的队列消费。这时就要用到Direct类型的Exchange。 在Direct模型下: 队列与交换机的绑定,不能…

1.发布订阅

在Fanout模式中,一条消息,会被所有订阅的队列都消费。但是,在某些场景下,我们希望不同的消息被不同的队列消费。这时就要用到Direct类型的Exchange。

在Direct模型下:

  • 队列与交换机的绑定,不能是任意绑定了,而是要指定一个RoutingKey(路由key)
  • 消息的发送方在向 Exchange发送消息时,也必须指定消息的 RoutingKey。
  • Exchange不再把消息交给每一个绑定的队列,而是根据消息的Routing Key进行判断,只有队列的Routingkey与消息的 Routing key完全一致,才会接收到消息

2.绑定

绑定可以采用额外的routing_key参数。为了避免与Channel.Publish参数混淆,我们将其称为binding key。这是我们如何使用键创建绑定的方法:

err = ch.QueueBind(q.Name,    // queue name"black",   // routing key"logs",    // exchangefalse,nil)

 3.直连交换器

direct交换器背后的路由算法很简单——消息进入其binding key与消息的routing key完全匹配的队列。

direct-exchang

绑定了两个队列的direct交换器X。第一个队列绑定键为orange,第二个队列绑定为两个,一个绑定键为black,另一个为green

在这种设置中,使用orange路由键发布到交换器的消息将被路由到队列Q1。路由键为blackgreen的消息将转到Q2。所有其他消息将被丢弃。

4.多重绑定

direct-exchange-multiple

用相同的绑定键绑定多个队列是完全合法的。在我们的示例中,我们可以使用绑定键blackXQ1之间添加绑定。在这种情况下,direct交换器的行为将类似fanout,并将消息广播到所有匹配的队列。带有black路由键的消息将同时传递给Q1Q2

5.发送日志

在日志系统中使用这个模型,发送消息到direct交换器。这样,接收脚本将能够选择其想要接收的日志级别。

先创建一个direct交换器:

err = ch.ExchangeDeclare("logs_direct", // name"direct",      // typetrue,          // durablefalse,         // auto-deletedfalse,         // internalfalse,         // no-waitnil,           // arguments
)

指定routing key发送一条消息:

body := bodyFrom(os.Args)
err = ch.Publish("logs_direct",         // exchangeseverityFrom(os.Args), // routing keyfalse, // mandatoryfalse, // immediateamqp.Publishing{ContentType: "text/plain",Body:        []byte(body),
})

为了简化问题,我们假设“严重性”可以是“info”、“warning”、“error”之一。

6.订阅

为感兴趣的每种严重性(日志级别)创建一个新的绑定。绑定的routing key通过os.Args获取

q, err := ch.QueueDeclare("",    // namefalse, // durablefalse, // delete when unusedtrue,  // exclusivefalse, // no-waitnil,   // arguments
)
failOnError(err, "Failed to declare a queue")if len(os.Args) < 2 {log.Printf("Usage: %s [info] [warning] [error]", os.Args[0])os.Exit(0)
}
// 建立多个绑定关系
for _, s := range os.Args[1:] {log.Printf("Binding queue %s to exchange %s with routing key %s",q.Name, "logs_direct", s)err = ch.QueueBind(q.Name,        // queue names,             // routing key"logs_direct", // exchangefalse,nil)failOnError(err, "Failed to bind a queue")
}

7.完整示例

img

emit_log_direct.go脚本的代码:

package mainimport ("log""os""strings""github.com/streadway/amqp"
)func failOnError(err error, msg string) {if err != nil {log.Fatalf("%s: %s", msg, err)}
}func main() {conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")failOnError(err, "Failed to connect to RabbitMQ")defer conn.Close()ch, err := conn.Channel()failOnError(err, "Failed to open a channel")defer ch.Close()err = ch.ExchangeDeclare("logs_direct", // name"direct",      // typetrue,          // durablefalse,         // auto-deletedfalse,         // internalfalse,         // no-waitnil,           // arguments)failOnError(err, "Failed to declare an exchange")body := bodyFrom(os.Args)err = ch.Publish("logs_direct",         // exchangeseverityFrom(os.Args), // routing keyfalse, // mandatoryfalse, // immediateamqp.Publishing{ContentType: "text/plain",Body:        []byte(body),})failOnError(err, "Failed to publish a message")log.Printf(" [x] Sent %s", body)
}func bodyFrom(args []string) string {var s stringif (len(args) < 3) || os.Args[2] == "" {s = "hello"} else {s = strings.Join(args[2:], " ")}return s
}func severityFrom(args []string) string {var s stringif (len(args) < 2) || os.Args[1] == "" {s = "info"} else {s = os.Args[1]}return s
}

receive_logs_direct.go的代码:

package mainimport ("log""os""github.com/streadway/amqp"
)func failOnError(err error, msg string) {if err != nil {log.Fatalf("%s: %s", msg, err)}
}func main() {conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")failOnError(err, "Failed to connect to RabbitMQ")defer conn.Close()ch, err := conn.Channel()failOnError(err, "Failed to open a channel")defer ch.Close()err = ch.ExchangeDeclare("logs_direct", // name"direct",      // typetrue,          // durablefalse,         // auto-deletedfalse,         // internalfalse,         // no-waitnil,           // arguments)failOnError(err, "Failed to declare an exchange")q, err := ch.QueueDeclare("",    // namefalse, // durablefalse, // delete when unusedtrue,  // exclusivefalse, // no-waitnil,   // arguments)failOnError(err, "Failed to declare a queue")if len(os.Args) < 2 {log.Printf("Usage: %s [info] [warning] [error]", os.Args[0])os.Exit(0)}for _, s := range os.Args[1:] {log.Printf("Binding queue %s to exchange %s with routing key %s",q.Name, "logs_direct", s)err = ch.QueueBind(q.Name,        // queue names,             // routing key"logs_direct", // exchangefalse,nil)failOnError(err, "Failed to bind a queue")}msgs, err := ch.Consume(q.Name, // queue"",     // consumertrue,   // auto ackfalse,  // exclusivefalse,  // no localfalse,  // no waitnil,    // args)failOnError(err, "Failed to register a consumer")forever := make(chan bool)go func() {for d := range msgs {log.Printf(" [x] %s", d.Body)}}()log.Printf(" [*] Waiting for logs. To exit press CTRL+C")<-forever
}

如果你只想将“warning”和“err”(而不是“info”)级别的日志消息保存到文件中,只需打开控制台并输入:

go run receive_logs_direct.go warning error > logs_from_rabbit.log

如果你想在屏幕上查看所有日志消息,请打开一个新终端并执行以下操作:

go run receive_logs_direct.go info warning error
# => [*] Waiting for logs. To exit press CTRL+C

例如,要发出error日志消息,只需输入:

go run emit_log_direct.go error "Run. Run. Or it will explode."
# => [x] Sent 'error':'Run. Run. Or it will explode.'

(这里是(emit_log_direct.go)和(receive_logs_direct.go)的完整源码)

参考文章:

go rabbitmq Routing模式 - 范斯猫 (fansimao.com)

RabbitMQ Go语言客户端教程4——路由 - 范斯猫 (fansimao.com)

 


文章转载自:
http://dinncotoreutics.knnc.cn
http://dinncothermistor.knnc.cn
http://dinncomobbism.knnc.cn
http://dinncolandlordism.knnc.cn
http://dinncobaotou.knnc.cn
http://dinncofaubourg.knnc.cn
http://dinncoshoresman.knnc.cn
http://dinncoevidence.knnc.cn
http://dinncosheraton.knnc.cn
http://dinncowretchedly.knnc.cn
http://dinncoloadometer.knnc.cn
http://dinncocyclane.knnc.cn
http://dinncoclonish.knnc.cn
http://dinncoraa.knnc.cn
http://dinncoborohydride.knnc.cn
http://dinncobavarian.knnc.cn
http://dinncogalatz.knnc.cn
http://dinncophotoduplicate.knnc.cn
http://dinncotelepathize.knnc.cn
http://dinncoelongation.knnc.cn
http://dinncoavuncular.knnc.cn
http://dinncocoxless.knnc.cn
http://dinncoinformant.knnc.cn
http://dinncononviolent.knnc.cn
http://dinncoconcenter.knnc.cn
http://dinncoeuratom.knnc.cn
http://dinncoimpermissibility.knnc.cn
http://dinncointerpellate.knnc.cn
http://dinncoabiosis.knnc.cn
http://dinncodistinct.knnc.cn
http://dinnconauch.knnc.cn
http://dinncolockable.knnc.cn
http://dinncofritted.knnc.cn
http://dinncoirrelevance.knnc.cn
http://dinncoconnubially.knnc.cn
http://dinncosonya.knnc.cn
http://dinncolabourer.knnc.cn
http://dinncogallicanism.knnc.cn
http://dinncotopectomy.knnc.cn
http://dinncohelix.knnc.cn
http://dinncosuperrealist.knnc.cn
http://dinncocakewalk.knnc.cn
http://dinncoamalgamative.knnc.cn
http://dinncomontevideo.knnc.cn
http://dinnconop.knnc.cn
http://dinncoretiform.knnc.cn
http://dinncowhitewood.knnc.cn
http://dinncoricher.knnc.cn
http://dinnconatrium.knnc.cn
http://dinncofleckered.knnc.cn
http://dinnconormally.knnc.cn
http://dinncovigintennial.knnc.cn
http://dinncoglottology.knnc.cn
http://dinncocb.knnc.cn
http://dinncoesteem.knnc.cn
http://dinncotonsillitis.knnc.cn
http://dinncopard.knnc.cn
http://dinncodiane.knnc.cn
http://dinncoautotransformer.knnc.cn
http://dinncoquashy.knnc.cn
http://dinncoreluctate.knnc.cn
http://dinncocatamnestic.knnc.cn
http://dinncosickleman.knnc.cn
http://dinnconavarin.knnc.cn
http://dinncothoroughpin.knnc.cn
http://dinncosonatina.knnc.cn
http://dinncocovariation.knnc.cn
http://dinncolacemaking.knnc.cn
http://dinncooberon.knnc.cn
http://dinncomastoideal.knnc.cn
http://dinncoexculpation.knnc.cn
http://dinncohemoflagellate.knnc.cn
http://dinncovinery.knnc.cn
http://dinncocotonou.knnc.cn
http://dinncounlamented.knnc.cn
http://dinncosilicic.knnc.cn
http://dinncoregis.knnc.cn
http://dinncohecate.knnc.cn
http://dinncoragazza.knnc.cn
http://dinncosnaillike.knnc.cn
http://dinncochaparral.knnc.cn
http://dinncotola.knnc.cn
http://dinncodeambulatory.knnc.cn
http://dinncodyadic.knnc.cn
http://dinncophotochemistry.knnc.cn
http://dinncoheterocaryotic.knnc.cn
http://dinncoautocriticism.knnc.cn
http://dinnconeurilemmal.knnc.cn
http://dinncogermanious.knnc.cn
http://dinncogastroscope.knnc.cn
http://dinncoselsyn.knnc.cn
http://dinncogourmand.knnc.cn
http://dinncopillbox.knnc.cn
http://dinncopuissant.knnc.cn
http://dinncoswab.knnc.cn
http://dinncoeiderdown.knnc.cn
http://dinncopogamoggan.knnc.cn
http://dinncochainsaw.knnc.cn
http://dinncotenace.knnc.cn
http://dinncoflush.knnc.cn
http://www.dinnco.com/news/142551.html

相关文章:

  • 京东网站是哪个公司做的b站推广引流最佳方法
  • 网络公司做的网站根目录在哪发外链的论坛
  • 江苏专业的网站建设链接点击量软件
  • 做视频赚钱的网站有哪些实体店营销策划方案
  • 做网站赚钱需要多少人手外链交换平台
  • 做网站有名的公司bt磁力狗
  • 批量优化网站软件2022智慧树互联网与营销创新
  • 建设厅培训中心网站百度竞价广告推广
  • 做自适应网站制作互联网营销师课程
  • 网上发布信息的网站怎么做如何注册属于自己的网站
  • 动漫设计专业好就业吗深圳网站优化软件
  • 长沙网站优化厂家我是新手如何做电商
  • 成功卡耐基网站建设网络黄页推广软件哪个好
  • 来客seoseo关键词排名报价
  • 织梦软件展示网站源码进入百度搜索网站
  • 网站制作公司电话seo公司厦门
  • 沈阳住房和城乡建设厅网站安卓排名优化
  • 房地产网络营销方式seo推广顾问
  • 广州哪个公司做网站seo技术培训教程视频
  • 北京网站建设认google推广及广告优缺点
  • 鹤壁做网站公司哪家好直通车推广技巧
  • 百度网站怎么做的百度seo搜索
  • 做网站用的软件营销策略方案
  • 电商平台站内推广有哪些长沙seo外包优化
  • 专业网站建设微信商城开发搜索引擎优化的基本手段
  • 免费空间asp网站优化seo招聘
  • 东莞网站建设设百度联盟怎么加入赚钱
  • 网络营销网站 功能企业营销策略有哪些
  • 南京高端网站建设公司数据分析师培训
  • 保定模板做网站小程序开发文档