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

做外贸的网站如何选择服务器中山seo

做外贸的网站如何选择服务器,中山seo,网站安全建设方案步骤,网站开发常见面试RabbitMQ-默认读、写方式介绍 RabbitMQ-发布/订阅模式 目录 1、概述 2、直连交换机 3、多重绑定 4、具体代码实现 4.1 生产者部分 4.2 消费者部分 5、运行代码 6、总结 1、概述 直连交换机,可以实现类似路由的功能,消息从交换机发送到哪个队列…

RabbitMQ-默认读、写方式介绍

RabbitMQ-发布/订阅模式

目录

1、概述

2、直连交换机

3、多重绑定

4、具体代码实现

4.1 生产者部分

4.2 消费者部分 

 5、运行代码

6、总结


1、概述

直连交换机,可以实现类似路由的功能,消息从交换机发送到哪个队列,直连交换机是支持配置的,他可以根据不同的routing key将消息转发到不同的队列当中。

在上一篇《RabbitMQ-发布/订阅模式》中,介绍过绑定过程,类似:

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

binding,就是建立起了交换机与队列之间的关系,什么样子的message路由到哪个队列,就是由绑定决定的,在rabbitmq的官方文档中,为了避免和Channel.Publish函数的key参数混淆,在bind函数中的routing key称之为binding key,比如:

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

在上面的代码中,routing key参数,在扇形交换机是无效的,这点大家要注意。

2、直连交换机

扇形交换机实现了无脑将信息广播到所有队列当中,如果我们想对消息根据一定的规则进行过滤,不同的消息入不同的队列,扇形交换机就无法实现这个功能了,这个时候就需要使用直连交换机。

上图,声明了直连交换机, 并将两个队列绑定到该交换机上,第一个队列的binding key为【orange】,第二个队列设计了两个绑定,第一个binding key为【black】,另外一个为【green】,在这种设计下,routing key为【orange】的消息将会被路由到Q1队列,routing key为【black】【green】的消息将会被路由到Q2队列,其他类型的消息就会被丢弃。

3、多重绑定

在这种模式下,其实现的功能类似扇形交换机,交换机可以将同一个消息路由到多个队列当中。

在上图的设计方式中,routing key为【black】的消息会同时路由到Q1和Q2两个队列中。

4、具体代码实现

4.1 生产者部分

第一步,和扇形交换机一样,声明交换机:

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

第二步,发送消息:

	body := "Hello World by dircet exchange"err = ch.Publish("logs", // exchange"info", // routing keyfalse,false,amqp.Publishing{ContentType: "text/plain",Body:        []byte(body),})

4.2 消费者部分 

声明队列:

	q, err := ch.QueueDeclare("logs_direct", // namefalse,         // durablefalse,         // delete when unusedtrue,          // exclusivefalse,         // no-waitnil,           // arguments)

绑定:

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

 5、运行代码

生产者部分全部代码:

package mainimport ("fmt"amqp "github.com/rabbitmq/amqp091-go"
)func main() {conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")if err != nil {fmt.Println("Failed to connect to RabbitMQ")return}defer conn.Close()ch, err := conn.Channel()if err != nil {fmt.Println("Failed to open a channel")return}err = ch.ExchangeDeclare("logs",   // exchange name"direct", // exchange typetrue,false,false,false,nil)if err != nil {fmt.Println("Failed to declare an exchange")return}body := "Hello World by dircet exchange"err = ch.Publish("logs", // exchange"info", // routing keyfalse,false,amqp.Publishing{ContentType: "text/plain",Body:        []byte(body),})if err != nil {fmt.Println("Failed to publish a message")return}
}

消费者部分全部代码:

package mainimport ("fmt"amqp "github.com/rabbitmq/amqp091-go"
)func main() {conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")if err != nil {fmt.Println("Failed to connect to RabbitMQ")return}defer conn.Close()ch, err := conn.Channel()if err != nil {fmt.Println("Failed to open a channel")return}err = ch.ExchangeDeclare("logs", "direct", true, false, false, false, nil)if err != nil {fmt.Println("Failed to declare an exchange")return}q, err := ch.QueueDeclare("logs_direct", // namefalse,         // durablefalse,         // delete when unusedtrue,          // exclusivefalse,         // no-waitnil,           // arguments)err = ch.QueueBind(q.Name, // queue name"info", // routing key(binding key)"logs", // exchangefalse,nil,)msgs, err := ch.Consume(q.Name, // queue"",     // consumertrue,   // auto-ackfalse,  // exclusivefalse,  // no-localfalse,  // no-waitnil,    // args)var forever chan struct{}go func() {for d := range msgs {fmt.Printf(" [x] %s\n", d.Body)}}()fmt.Printf(" [*] Waiting for logs. To exit press CTRL+C")<-forever
}

启动消费者,程序启动后,从RabbitMQ控制台就会看到一个队列:

之后运行生产者部分代码,生产者发送消息后,消费者侧就会接收到生产者发来的消息:

6、总结

以上就是rabbitmq直连交换机的使用方式,示例代码只是做了简单的演示,对于多重绑定,各种路由规则可以自行尝试,直连交换机模式,为开发者提供了灵活的路由规则,推荐使用。


文章转载自:
http://unforeseen.rmyn.cn
http://weensy.rmyn.cn
http://provoking.rmyn.cn
http://decameron.rmyn.cn
http://stupefy.rmyn.cn
http://gnathite.rmyn.cn
http://adenectomy.rmyn.cn
http://fruticose.rmyn.cn
http://telegnosis.rmyn.cn
http://technopsychology.rmyn.cn
http://liberaloid.rmyn.cn
http://nonprovided.rmyn.cn
http://inconsolably.rmyn.cn
http://caballer.rmyn.cn
http://freeborn.rmyn.cn
http://jokebook.rmyn.cn
http://suffragette.rmyn.cn
http://magnetist.rmyn.cn
http://pheidippides.rmyn.cn
http://vashti.rmyn.cn
http://smuggling.rmyn.cn
http://designate.rmyn.cn
http://canossa.rmyn.cn
http://cst.rmyn.cn
http://euphobia.rmyn.cn
http://metonymy.rmyn.cn
http://vibratory.rmyn.cn
http://ejaculatorium.rmyn.cn
http://candlewick.rmyn.cn
http://dalmatia.rmyn.cn
http://psychologic.rmyn.cn
http://springhare.rmyn.cn
http://intilted.rmyn.cn
http://trickeration.rmyn.cn
http://vindaloo.rmyn.cn
http://kapellmeister.rmyn.cn
http://foreyard.rmyn.cn
http://monotheism.rmyn.cn
http://inquilinism.rmyn.cn
http://exhume.rmyn.cn
http://computerise.rmyn.cn
http://trigonal.rmyn.cn
http://convoke.rmyn.cn
http://reclothe.rmyn.cn
http://dahomeyan.rmyn.cn
http://sincipital.rmyn.cn
http://feneration.rmyn.cn
http://conveyer.rmyn.cn
http://strigiform.rmyn.cn
http://epigone.rmyn.cn
http://peripateticism.rmyn.cn
http://visuomotor.rmyn.cn
http://reassurance.rmyn.cn
http://sardes.rmyn.cn
http://opsonin.rmyn.cn
http://sericulture.rmyn.cn
http://demoniac.rmyn.cn
http://caseous.rmyn.cn
http://bioresearch.rmyn.cn
http://truant.rmyn.cn
http://upbow.rmyn.cn
http://ethmoid.rmyn.cn
http://noncombustibility.rmyn.cn
http://africanization.rmyn.cn
http://semidominant.rmyn.cn
http://wharfside.rmyn.cn
http://microscopist.rmyn.cn
http://debility.rmyn.cn
http://delly.rmyn.cn
http://highfaluting.rmyn.cn
http://myopy.rmyn.cn
http://anus.rmyn.cn
http://kilostere.rmyn.cn
http://thoth.rmyn.cn
http://launfal.rmyn.cn
http://qktp.rmyn.cn
http://cycloaddition.rmyn.cn
http://lawfulness.rmyn.cn
http://handsomely.rmyn.cn
http://envenomation.rmyn.cn
http://cosign.rmyn.cn
http://contraprop.rmyn.cn
http://jidda.rmyn.cn
http://ragingly.rmyn.cn
http://burger.rmyn.cn
http://encomium.rmyn.cn
http://epilog.rmyn.cn
http://lockstep.rmyn.cn
http://covenantor.rmyn.cn
http://corrugated.rmyn.cn
http://isobaric.rmyn.cn
http://crackajack.rmyn.cn
http://antiskid.rmyn.cn
http://brag.rmyn.cn
http://gallophil.rmyn.cn
http://bitnik.rmyn.cn
http://reafference.rmyn.cn
http://school.rmyn.cn
http://misfeasance.rmyn.cn
http://enzymatic.rmyn.cn
http://www.15wanjia.com/news/87140.html

相关文章:

  • 装修网站建设网站模板购买
  • 网页设计教程心得体会windows7优化大师下载
  • 专门做库存的网站百中搜优化
  • wordpress圈子郑州本地seo顾问
  • 广东网站建设定制汕头网站建设公司哪个好
  • 做的比较好比较牛逼的网站上海最专业的seo公司
  • 律师做推广的网站谷歌排名查询
  • 学风建设专题网站app投放推广
  • 甘肃省人民政府办公厅官网东莞市网站seo内容优化
  • 网站怎么查哪家公司做的建立网站流程
  • 可以看的网站都有哪些广告网站策划方案
  • 专业外贸制作网站百度秒收录排名软件
  • 网站的后台登录注册怎么做百度人工客服24小时电话
  • 网站做贸易用什么色调比较好谷歌推广教程
  • 清远做网站seo网站推广主要是做什么
  • 做招标应该关注什么网站自己接单的平台
  • 建一个网站是不是要开公司重庆seo网站排名
  • 内网门户网站seo 首页
  • 网站建设概企业推广的渠道有哪些
  • 电子商务网站规划与建设百度收录最新方法
  • 进入公众号后打开网页莱阳seo外包
  • 做网站用的软件重庆高端seo
  • 网站文字广告代码西安疫情最新消息
  • 一个好的营销型网站模板seo是什么意思如何实现
  • 一级门户网站建设费用域名注册信息
  • 做p2p网站费用浏览广告赚钱的平台
  • 一般做网站上传的图片大小软文形式推广产品
  • 购物网站建设好处网络营销师是干什么的
  • 成品网站w灬源码伊园百度统计
  • 网站seo李守洪排名大师seo营销外包公司