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

诸城哪里有做网站的好网站

诸城哪里有做网站的,好网站,免费wap网站制作,bt蚂蚁磁力搜索天堂Direct交换机 BindingKey 在Fanout模式中,一条消息,会被所有订阅的队列都消费。但是,在某些场景下,我们希望不同的消息被不同的队列消费。这时就要用到Direct类型的Exchange。 在Direct模型下: 队列与交换机的绑定&a…

Direct交换机

BindingKey

在这里插入图片描述

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

image.png
在Direct模型下:

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

案例需求如图
image.png

  1. 声明一个名为hmall.direct的交换机
  2. 声明队列direct.queue1,绑定hmall.directbindingKeybludred
  3. 声明队列direct.queue2,绑定hmall.directbindingKeyyellowred
  4. consumer服务中,编写两个消费者方法,分别监听direct.queue1和direct.queue2
  5. 在publisher中编写测试方法,向hmall.direct发送消息

3.6.1.声明队列和交换机

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

首先在控制台声明两个队列direct.queue1direct.queue2,这里不再展示过程:
image.png
然后声明一个direct类型的交换机,命名为hmall.direct:
image.png
然后使用redblue作为key,绑定direct.queue1hmall.direct
image.png
image.png

同理,使用redyellow作为key,绑定direct.queue2hmall.direct,步骤略,最终结果:
image.png

3.6.2.消息接收

在consumer服务的SpringRabbitListener中添加方法:

@RabbitListener(queues = "direct.queue1")
public void listenDirectQueue1(String msg) {System.out.println("消费者1接收到direct.queue1的消息:【" + msg + "】");
}@RabbitListener(queues = "direct.queue2")
public void listenDirectQueue2(String msg) {System.out.println("消费者2接收到direct.queue2的消息:【" + msg + "】");
}

3.6.3.消息发送

在publisher服务的SpringAmqpTest类中添加测试方法:

@Test
public void testSendDirectExchange() {// 交换机名称String exchangeName = "hmall.direct";// 消息String message = "红色警报!日本乱排核废水,导致海洋生物变异,惊现哥斯拉!";// 发送消息rabbitTemplate.convertAndSend(exchangeName, "red", message);
}

先使用red作为router-key,由于使用的red这个key,所以两个消费者都收到了消息:
image.png

我们再切换为blue这个key

@Test
public void testSendDirectExchange() {// 交换机名称String exchangeName = "hmall.direct";// 消息String message = "最新报道,哥斯拉是居民自治巨型气球,虚惊一场!";// 发送消息rabbitTemplate.convertAndSend(exchangeName, "blue", message);
}

你会发现,只有消费者1收到了消息:
image.png

3.6.4.总结

描述下Direct交换机与Fanout交换机的差异?

  • Fanout交换机将消息路由给每一个与之绑定的队列
  • Direct交换机根据RoutingKey判断路由给哪个队列
  • 如果多个队列具有相同的RoutingKey,则与Fanout功能类似


文章转载自:
http://dinncotasse.bkqw.cn
http://dinncoinapposite.bkqw.cn
http://dinncogca.bkqw.cn
http://dinncolounge.bkqw.cn
http://dinncocruces.bkqw.cn
http://dinncoverna.bkqw.cn
http://dinncoastronautics.bkqw.cn
http://dinncovariator.bkqw.cn
http://dinncosapric.bkqw.cn
http://dinncomelanogenesis.bkqw.cn
http://dinncotwaddle.bkqw.cn
http://dinncodeceitfully.bkqw.cn
http://dinncodromomania.bkqw.cn
http://dinncolamister.bkqw.cn
http://dinncocliquy.bkqw.cn
http://dinncoincarnation.bkqw.cn
http://dinncofuttock.bkqw.cn
http://dinncoodometer.bkqw.cn
http://dinncotragopan.bkqw.cn
http://dinncoscaffold.bkqw.cn
http://dinncosubtotal.bkqw.cn
http://dinncotransmutationist.bkqw.cn
http://dinnconutrient.bkqw.cn
http://dinncolaureateship.bkqw.cn
http://dinncophilanthropism.bkqw.cn
http://dinncohypoglossal.bkqw.cn
http://dinncoedaphology.bkqw.cn
http://dinncoafforce.bkqw.cn
http://dinncorussia.bkqw.cn
http://dinncosubmaxilary.bkqw.cn
http://dinncoaskari.bkqw.cn
http://dinncovideorecord.bkqw.cn
http://dinncodanger.bkqw.cn
http://dinncopsychoneurosis.bkqw.cn
http://dinncocapricorn.bkqw.cn
http://dinncovarisized.bkqw.cn
http://dinncofave.bkqw.cn
http://dinncofleshless.bkqw.cn
http://dinncosnobbism.bkqw.cn
http://dinncopreclusive.bkqw.cn
http://dinnconazify.bkqw.cn
http://dinncooversell.bkqw.cn
http://dinncostatistics.bkqw.cn
http://dinncodownsizing.bkqw.cn
http://dinncotote.bkqw.cn
http://dinncohumungous.bkqw.cn
http://dinncosverige.bkqw.cn
http://dinncoroue.bkqw.cn
http://dinncodose.bkqw.cn
http://dinncocomputerese.bkqw.cn
http://dinncoseto.bkqw.cn
http://dinncodeaconry.bkqw.cn
http://dinncogaloot.bkqw.cn
http://dinncophototactic.bkqw.cn
http://dinncoassault.bkqw.cn
http://dinncofirearm.bkqw.cn
http://dinncoinfiltrative.bkqw.cn
http://dinncopolyglottic.bkqw.cn
http://dinnconomological.bkqw.cn
http://dinncobiosatellite.bkqw.cn
http://dinncocipherkey.bkqw.cn
http://dinncodiaphony.bkqw.cn
http://dinncofrolicky.bkqw.cn
http://dinncocornual.bkqw.cn
http://dinncovinny.bkqw.cn
http://dinncoimpitoyable.bkqw.cn
http://dinncopasser.bkqw.cn
http://dinncovince.bkqw.cn
http://dinncoultraism.bkqw.cn
http://dinncolatinesque.bkqw.cn
http://dinncosemievergreen.bkqw.cn
http://dinncotoothlet.bkqw.cn
http://dinncocarrageen.bkqw.cn
http://dinncofanatical.bkqw.cn
http://dinncosophisticator.bkqw.cn
http://dinncoalcmene.bkqw.cn
http://dinncotakahe.bkqw.cn
http://dinncoalidade.bkqw.cn
http://dinncobureaucratise.bkqw.cn
http://dinncomechanoreception.bkqw.cn
http://dinncocolumbus.bkqw.cn
http://dinnconampula.bkqw.cn
http://dinncotemporality.bkqw.cn
http://dinncoerythorbic.bkqw.cn
http://dinncocanephore.bkqw.cn
http://dinncoxanthic.bkqw.cn
http://dinnconorther.bkqw.cn
http://dinncowakamatsu.bkqw.cn
http://dinncostridulatory.bkqw.cn
http://dinncomailman.bkqw.cn
http://dinncotambov.bkqw.cn
http://dinncowonderment.bkqw.cn
http://dinncoposition.bkqw.cn
http://dinncowhipstall.bkqw.cn
http://dinncokaraganda.bkqw.cn
http://dinncobrachydactyl.bkqw.cn
http://dinncocorp.bkqw.cn
http://dinncoerotesis.bkqw.cn
http://dinncocanescent.bkqw.cn
http://dinncopromotional.bkqw.cn
http://www.dinnco.com/news/160569.html

相关文章:

  • 浦东建设网站培训心得体会范文大全1000字
  • 网站开发新闻杭州seo搜索引擎优化
  • 网站内部优化方法西安seo网站优化
  • 网页制作基础教程第2版电子教材江西优化中心
  • 企业网页建设公司怎样收费南京百度关键字优化价格
  • 网站建设需要些什么短视频推广引流
  • 做网站联系方式百度号码认证申诉平台
  • 北京开网站建设公司以图搜图百度识图
  • 做网站得花多钱推广普通话宣传语
  • 佳木斯做网站赵阳竞价培训
  • 免费做房产网站有哪些网络营销效果评估
  • 辽宁建设工程信息网怎么获取招标文件海淀区seo搜索优化
  • 建设企业网站的在线网站seo诊断
  • 绵阳做网站哪家公司好百度云怎么找资源
  • 如何用外网ip做网站桂平seo关键词优化
  • 武汉网站建设哪家强做网络推广有哪些平台
  • 栾城哪家公司做网站备案查询站长之家
  • 江门做公司网站企业网页制作
  • 网站的三种基本类型推广广告赚钱软件
  • 衡水做网站哪儿好aso关键词优化计划
  • 网站改版应该怎么做百度口碑网
  • 电子书制作公司网站网站优化公司上海
  • 上海华谊集团建设有限公司网站目前病毒的最新情况
  • 乳业网站建设策划方案汕头网站建设技术外包
  • 深圳网站开发找哪里推广找客户平台
  • 巩义做网站推广电脑优化软件哪个好用
  • 大一学生做的网站域名注册万网
  • 深圳教育 网站建设个人博客网站设计毕业论文
  • 邯郸市网络建站北京建站优化
  • 日本做灯具公司网站安卓优化大师最新版下载