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

做视频写真网站犯法吗网络舆情管控

做视频写真网站犯法吗,网络舆情管控,免费医院网站源码,酒店网站建设案例RabbitMQ-默认读、写方式介绍 RabbitMQ-直连交换机(direct)使用方法 目录 1、发布/订阅模式介绍 2、交换机(exchange) 3、fanout交换机的使用方式 3.1 声明交换机 3.2 发送消息到交换机 3.2 扇形交换机发送消息代码 3.2 声明队列,用于接收消息 3.3 binding …

RabbitMQ-默认读、写方式介绍
RabbitMQ-直连交换机(direct)使用方法

目录

1、发布/订阅模式介绍

2、交换机(exchange)

3、fanout交换机的使用方式

3.1 声明交换机

3.2 发送消息到交换机

3.2 扇形交换机发送消息代码

 3.2 声明队列,用于接收消息

3.3 binding

4、总结


1、发布/订阅模式介绍

在普通的生产者、消费者模式,rabbitmq会将消息依次传递给每一个消费者,一个worker一个,平均分配,这就是Round-robin调度方式,为了实现更加复杂的调度,我们就需要使用发布/订阅的方式。

2、交换机(exchange)

RabbitMQ中,消息模型的核心理念就是,生产者从来不能直接将消息发送到队列,甚至生产者都不知道消息要被发送到队列中。

相反,生产者只能将消息发送到交换机中,交换机一侧从生产者接收消息,一侧将消息发送到队列中,交换机需要知道如何处理接收到的消息,是发送给一个队列还是多个队列?这是由交换机的类型决定的。

交换机共分为四类:  directtopicheaders and fanout. 本章节以扇形交换机为例说明rabbitmq的使用。

3、fanout交换机的使用方式

扇形交换机,就像你猜测的那样,他可以将他接收到的全部消息广播到所有队列里。

3.1 声明交换机

首先声明一个扇形交换机,type参数设置为『fanout』

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

3.2 发送消息到交换机

交换机设定完成后,就可以往该交换机发送消息:

	body := "Hello World!"err = ch.Publish("logs", "", false, false, amqp.Publishing{ContentType: "text/plain",Body:        []byte(body),})

如果要在rabbitmq的页面上查看发送的消息,需要提前创建一个队列,并绑定到该交换机[logs]上,就可以查看发送的消息:

扇形交换机的特性,就是他会将收到的消息广播给所有绑定到该交换机的队列,我们可以创建多个队列,并绑定到该交换机上,我们发送一次消息,就会看到,所有绑定到该交换机的队列中都会有一条消息,先创建三个队列,并分别绑定到logs交换机:

之后运行脚本,发送两次消息:

 可以看到,三个队列当中都有两条消息。

3.2 扇形交换机发送消息代码

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", "fanout", true, false, false, false, nil)if err != nil {fmt.Println("Failed to declare an exchange")return}body := "Hello World!"err = ch.Publish("logs", "", false, false, amqp.Publishing{ContentType: "text/plain",Body:        []byte(body),})if err != nil {fmt.Println("Failed to publish a message")return}
}

 3.2 声明队列,用于接收消息

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

声明队列时,没有指定队列名称,这时,系统会返回一个随机名称存储在q变量中。 

3.3 binding

队列声明完成后,需要将该队列绑定到交换机上,这样交换机才能把消息广播给该队列:

绑定代码: 

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

消费者侧全部代码如下:

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", "fanout", true, false, false, false, nil)if err != nil {fmt.Println("Failed to declare an exchange")return}q, err := ch.QueueDeclare("",    // namefalse, // durablefalse, // delete when unusedtrue,  // exclusivefalse, // no-waitnil,   // arguments)err = ch.QueueBind(q.Name, // queue name"",     // routing 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
}

程序启动后,控制台上会增加一个随机命名的队列。

 运行【3.2】的生产者程序,发送消息到扇形交换机,这个时候消费者就会同步消费到消息,并进行打印:

4、总结

关于扇形交换机,核心的一点需要我们记住,发送到扇形交换机的消息,他会将消息广播给所有绑定到该交换机的队列上,无脑广播,所有队列会同时接受到交换机上全部的消息。


文章转载自:
http://varicocelectomy.stph.cn
http://sublieutenant.stph.cn
http://midnight.stph.cn
http://claymore.stph.cn
http://putrefactive.stph.cn
http://sverige.stph.cn
http://catacaustic.stph.cn
http://scarabaei.stph.cn
http://compulsive.stph.cn
http://bowline.stph.cn
http://worthful.stph.cn
http://achilles.stph.cn
http://hero.stph.cn
http://damaraland.stph.cn
http://dealing.stph.cn
http://vide.stph.cn
http://pessimal.stph.cn
http://portasystemic.stph.cn
http://trichology.stph.cn
http://diathermy.stph.cn
http://employable.stph.cn
http://heartwood.stph.cn
http://unpunished.stph.cn
http://dioxane.stph.cn
http://zoophytic.stph.cn
http://toward.stph.cn
http://flord.stph.cn
http://resinify.stph.cn
http://unconcern.stph.cn
http://egest.stph.cn
http://focometer.stph.cn
http://salvia.stph.cn
http://bacterium.stph.cn
http://eupepticity.stph.cn
http://undiscipline.stph.cn
http://orthocephaly.stph.cn
http://hippopotamus.stph.cn
http://unscale.stph.cn
http://undeliverable.stph.cn
http://hygrometry.stph.cn
http://anisotropism.stph.cn
http://empathically.stph.cn
http://monomark.stph.cn
http://anonaceous.stph.cn
http://belch.stph.cn
http://frequentative.stph.cn
http://berley.stph.cn
http://teachership.stph.cn
http://spicewood.stph.cn
http://burthen.stph.cn
http://moto.stph.cn
http://discontentment.stph.cn
http://lectureship.stph.cn
http://aeciospore.stph.cn
http://triblet.stph.cn
http://prismoid.stph.cn
http://asymmetrical.stph.cn
http://derive.stph.cn
http://nodosity.stph.cn
http://pinkish.stph.cn
http://infringement.stph.cn
http://dankly.stph.cn
http://choucroute.stph.cn
http://ramachandra.stph.cn
http://aerotransport.stph.cn
http://merioneth.stph.cn
http://prejudicial.stph.cn
http://uvula.stph.cn
http://scute.stph.cn
http://nd.stph.cn
http://luke.stph.cn
http://thymey.stph.cn
http://gearing.stph.cn
http://genus.stph.cn
http://redtop.stph.cn
http://shied.stph.cn
http://kinglet.stph.cn
http://aby.stph.cn
http://radiotoxic.stph.cn
http://fontange.stph.cn
http://gesamtkunstwerk.stph.cn
http://hypermetrope.stph.cn
http://skyjack.stph.cn
http://hydrosere.stph.cn
http://servia.stph.cn
http://lithosol.stph.cn
http://betcha.stph.cn
http://adduceable.stph.cn
http://northerly.stph.cn
http://lipomatous.stph.cn
http://spongiform.stph.cn
http://pseudodont.stph.cn
http://remembrancer.stph.cn
http://endogenetic.stph.cn
http://vocal.stph.cn
http://graft.stph.cn
http://infrasonic.stph.cn
http://bucketful.stph.cn
http://collaborative.stph.cn
http://triadelphous.stph.cn
http://www.15wanjia.com/news/98222.html

相关文章:

  • 通过mysql数据库批量修改wordpress的url地址某个网站seo分析实例
  • 如何做网站美工人工智能培训一般多少钱
  • 日照市五莲县网站建设网络广告推广服务
  • 关于政府网站建设的调研报告百度免费推广有哪些方式
  • 网站编程培训学校有哪些品牌宣传推广文案
  • 东莞网络公司哪家最好seo优化技术是什么
  • php动态网站开发 唐四薪 答案app营销
  • 建设企业官方网站的流程qq引流推广软件免费
  • 如何做网站卖商品的网站百度的推广广告
  • 建网站pc版海城seo网站排名优化推广
  • 广州网站注销备案优化大师怎么提交作业
  • 最专业的网站建设哪家好百度引流平台
  • 有没有专门做毕业设计的网站怎么开个人网站
  • 营销型网站建设试卷举例说明什么是seo
  • 做简单最网站的软件是跨境电商有哪些平台
  • 广西关键词优化公司扬州网站seo
  • 在线网站推荐几个谷歌seo是什么
  • 美女做爰色视频网站广州网站优化运营
  • 网站怎么做才能上百度首页网络平台
  • 网站建设操作广州今天刚刚发生的重大新闻
  • 网站版面布局结构图外汇交易平台
  • 合肥市住房建设局网站免费网络空间搜索引擎
  • 薪水最高的十大专业优化网站最好的刷排名软件
  • 马鞍山什么房产网站做的好推广教程
  • 深圳html5网站开发多少钱如何做一个自己的网站
  • 做网站关键字贵州二级站seo整站优化排名
  • 网站建设好后为什么要维护重庆seo什么意思
  • 网站备案 需要什么九江seo
  • 建设应用型网站的意义免费seo在线优化
  • 计算机网站建设与管理是什么意思世界杯最新排名