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

乌鲁木齐市天山区有哪些幼儿园seo 优化是什么

乌鲁木齐市天山区有哪些幼儿园,seo 优化是什么,江苏建设通网站,莱芜论坛话题目录 一、序言二、配置文件application.yml三、RabbitMQ交换机和队列配置1、定义4个队列2、定义Fanout交换机和队列绑定关系2、定义Direct交换机和队列绑定关系3、定义Topic交换机和队列绑定关系4、定义Header交换机和队列绑定关系 四、RabbitMQ消费者配置五、RabbitMQ生产者六…

目录

  • 一、序言
  • 二、配置文件application.yml
  • 三、RabbitMQ交换机和队列配置
    • 1、定义4个队列
    • 2、定义Fanout交换机和队列绑定关系
    • 2、定义Direct交换机和队列绑定关系
    • 3、定义Topic交换机和队列绑定关系
    • 4、定义Header交换机和队列绑定关系
  • 四、RabbitMQ消费者配置
  • 五、RabbitMQ生产者
  • 六、测试用例
    • 1、发送到FanoutExchage
    • 2、发送到DirectExchage
    • 3、发送到TopicExchange
    • 4、发动到HeadersExchage
  • 七、结语

一、序言

在上一节 RabbitMQ中的核心概念和交换机类型 中我们介绍了RabbitMQ中的一些核心概念,尤其是各种交换机的类型,接下来我们将具体讲解各种交换机的配置和消息订阅实操。


二、配置文件application.yml

我们先上应用启动配置文件application.yml,如下:

server:port: 8080
spring:rabbitmq:addresses: localhost:5672username: adminpassword: adminvirtual-host: /listener:type: simplesimple:acknowledge-mode: autoconcurrency: 5max-concurrency: 20prefetch: 5

备注:这里我们指定了RabbitListenerContainerFactory的类型为SimpleRabbitListenerContainerFactory,并且指定消息确认模式为自动确认

三、RabbitMQ交换机和队列配置

Spring官方提供了一套 流式API 来定义队列交换机绑定关系,非常的方便,接下来我们定义4种类型的交换机和相应队列的绑定关系。

1、定义4个队列

/*** 定义4个队列*/
@Configuration
protected static class QueueConfig {@Beanpublic Queue queue1() {return QueueBuilder.durable("queue-1").build();}@Beanpublic Queue queue2() {return QueueBuilder.durable("queue-2").build();}@Beanpublic Queue queue3() {return QueueBuilder.durable("queue-3").build();}@Beanpublic Queue queue4() {return QueueBuilder.durable("queue-4").build();}
}

2、定义Fanout交换机和队列绑定关系

/*** 定义Fanout交换机和对应的绑定关系*/
@Configuration
protected static class FanoutExchangeBindingConfig {@Beanpublic FanoutExchange fanoutExchange() {return ExchangeBuilder.fanoutExchange("fanout-exchange").build();}/*** 定义多个Fanout交换机和队列的绑定关系* @param fanoutExchange* @param queue1* @param queue2* @param queue3* @param queue4* @return*/@Beanpublic Declarables bindQueueToFanoutExchange(FanoutExchange fanoutExchange, Queue queue1, Queue queue2, Queue queue3, Queue queue4) {Binding queue1Binding = BindingBuilder.bind(queue1).to(fanoutExchange);Binding queue2Binding = BindingBuilder.bind(queue2).to(fanoutExchange);Binding queue3Binding = BindingBuilder.bind(queue3).to(fanoutExchange);Binding queue4Binding = BindingBuilder.bind(queue4).to(fanoutExchange);return new Declarables(queue1Binding, queue2Binding, queue3Binding, queue4Binding);}}

备注:这里我们将4个队列绑定到了名为fanout-exchange的交换机上。

2、定义Direct交换机和队列绑定关系

@Configuration
protected static class DirectExchangeBindingConfig {@Beanpublic DirectExchange directExchange() {return ExchangeBuilder.directExchange("direct-exchange").build();}@Beanpublic Binding bindingQueue3ToDirectExchange(DirectExchange directExchange, Queue queue3) {return BindingBuilder.bind(queue3).to(directExchange).with("queue3-route-key");}
}

备注:这里我们定义了名为direct-exchange的交换机并通过路由keyqueue3-route-keyqueue-3绑定到了该交换机上。


3、定义Topic交换机和队列绑定关系

@Configuration
protected static class TopicExchangeBindingConfig {@Beanpublic TopicExchange topicExchange() {return ExchangeBuilder.topicExchange("topic-exchange").build();}@Beanpublic Declarables bindQueueToTopicExchange(TopicExchange topicExchange, Queue queue1, Queue queue2) {Binding queue1Binding = BindingBuilder.bind(queue1).to(topicExchange).with("com.order.*");Binding queue2Binding = BindingBuilder.bind(queue2).to(topicExchange).with("com.#");return new Declarables(queue1Binding, queue2Binding);}
}

这里我们定义了名为topic-exchange类型的交换机,该类型交换机支持路由key通配符匹配,*代表一个任意字符,#代表一个或多个任意字符。

备注:

  1. 通过路由keycom.order.*queue-1绑定到了该交换机上。
  2. 通过路由key com.#queue-2也绑定到了该交换机上。

4、定义Header交换机和队列绑定关系

@Configuration
protected static class HeaderExchangeBinding {@Beanpublic HeadersExchange headersExchange() {return ExchangeBuilder.headersExchange("headers-exchange").build();}@Beanpublic Binding bindQueueToHeadersExchange(HeadersExchange headersExchange, Queue queue4) {return BindingBuilder.bind(queue4).to(headersExchange).where("function").matches("logging");}
}

备注:这里我们定义了名为headers-exchange类型的交换机,并通过参数function=loggingqueue-4绑定到了该交换机上。


四、RabbitMQ消费者配置

Spring RabbitMQ中支持注解式监听端点配置,用于异步接收消息,如下:

@Slf4j
@Component
public class RabbitMqConsumer {@RabbitListener(queues = "queue-1")public void handleMsgFromQueue1(String msg) {log.info("Message received from queue-1, message body: {}", msg);}@RabbitListener(queues = "queue-2")public void handleMsgFromQueue2(String msg) {log.info("Message received from queue-2, message body: {}", msg);}@RabbitListener(queues = "queue-3")public void handleMsgFromQueue3(String msg) {log.info("Message received from queue-3, message body: {}", msg);}@RabbitListener(queues = "queue-4")public void handleMsgFromQueue4(String msg) {log.info("Message received from queue-4, message body: {}", msg);}
}

备注:这里我们分别定义了4个消费者,分别用来接受4个队列的消息。

五、RabbitMQ生产者

@Slf4j
@Component
@RequiredArgsConstructor
public class RabbitMqProducer {private final RabbitTemplate rabbitTemplate;public void sendMsgToFanoutExchange(String body) {log.info("开始发送消息到fanout-exchange, 消息体:{}", body);Message message = MessageBuilder.withBody(body.getBytes(StandardCharsets.UTF_8)).build();rabbitTemplate.send("fanout-exchange", StringUtils.EMPTY, message);}public void sendMsgToDirectExchange(String body) {log.info("开始发送消息到direct-exchange, 消息体:{}", body);Message message = MessageBuilder.withBody(body.getBytes(StandardCharsets.UTF_8)).build();rabbitTemplate.send("direct-exchange", "queue3-route-key", message);}public void sendMsgToTopicExchange(String routingKey, String body) {log.info("开始发送消息到topic-exchange, 消息体:{}", body);Message message = MessageBuilder.withBody(body.getBytes(StandardCharsets.UTF_8)).build();rabbitTemplate.send("topic-exchange", routingKey, message);}public void sendMsgToHeadersExchange(String body) {log.info("开始发送消息到headers-exchange, 消息体:{}", body);MessageProperties messageProperties = MessagePropertiesBuilder.newInstance().setHeader("function", "logging").build();Message message = MessageBuilder.withBody(body.getBytes(StandardCharsets.UTF_8)).andProperties(messageProperties).build();rabbitTemplate.send("headers-exchange", StringUtils.EMPTY, message);}}

六、测试用例

这里写了个简单的Controller用来测试,如下:

@RestController
@RequiredArgsConstructor
public class RabbitMsgController {private final RabbitMqProducer rabbitMqProducer;@RequestMapping("/exchange/fanout")public ResponseEntity<String> sendMsgToFanoutExchange(String body) {rabbitMqProducer.sendMsgToFanoutExchange(body);return ResponseEntity.ok("广播消息发送成功");}@RequestMapping("/exchange/direct")public ResponseEntity<String> sendMsgToDirectExchange(String body) {rabbitMqProducer.sendMsgToDirectExchange(body);return ResponseEntity.ok("消息发送到Direct交换成功");}@RequestMapping("/exchange/topic")public ResponseEntity<String> sendMsgToTopicExchange(String routingKey, String body) {rabbitMqProducer.sendMsgToTopicExchange(routingKey, body);return ResponseEntity.ok("消息发送到Topic交换机成功");}@RequestMapping("/exchange/headers")public ResponseEntity<String> sendMsgToHeadersExchange(String body) {rabbitMqProducer.sendMsgToHeadersExchange(body);return ResponseEntity.ok("消息发送到Headers交换机成功");}}

1、发送到FanoutExchage

直接访问http://localhost:8080/exchange/fanout?body=hello,可以看到该消息广播到了4个队列上。

2023-11-07 17:41:12.959  INFO 39460 --- [nio-8080-exec-9] c.u.r.i.producer.RabbitMqProducer        : 开始发送消息到fanout-exchange, 消息体:hello
2023-11-07 17:41:12.972  INFO 39460 --- [ntContainer#1-5] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-1, message body: hello
2023-11-07 17:41:12.972  INFO 39460 --- [ntContainer#0-4] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-4, message body: hello
2023-11-07 17:41:12.972  INFO 39460 --- [ntContainer#3-3] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-3, message body: hello
2023-11-07 17:41:12.972  INFO 39460 --- [ntContainer#2-4] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-2, message body: hello

2、发送到DirectExchage

访问http://localhost:8080/exchange/direct?body=hello,可以看到消息通过路由keyqueue3-route-key发送到了queue-3上。

2023-11-07 17:43:26.804  INFO 39460 --- [nio-8080-exec-1] c.u.r.i.producer.RabbitMqProducer        : 开始发送消息到direct-exchange, 消息体:hello
2023-11-07 17:43:26.822  INFO 39460 --- [ntContainer#3-5] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-3, message body: hello

3、发送到TopicExchange

访问http://localhost:8080/exchange/topic?body=hello&routingKey=com.order.create,路由key为 com.order.create的消息分别发送到了queue-1queue-2上。

2023-11-07 17:44:45.301  INFO 39460 --- [nio-8080-exec-4] c.u.r.i.producer.RabbitMqProducer        : 开始发送消息到topic-exchange, 消息体:hello
2023-11-07 17:44:45.312  INFO 39460 --- [ntContainer#1-3] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-1, message body: hello
2023-11-07 17:44:45.312  INFO 39460 --- [ntContainer#2-3] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-2, message body: hello

4、发动到HeadersExchage

访问http://localhost:8080/exchange/headers?body=hello,消息通过头部信息function=logging发送到了headers-exchange上。

2023-11-07 17:47:21.736  INFO 39460 --- [nio-8080-exec-9] c.u.r.i.producer.RabbitMqProducer        : 开始发送消息到headers-exchange, 消息体:hello
2023-11-07 17:47:21.749  INFO 39460 --- [ntContainer#0-3] c.u.r.i.consumer.RabbitMqConsumer        : Message received from queue-4, message body: hello

七、结语

下一节我们将会介绍通过两种方式借由RabbitMQ实现延迟消息发送和订阅,敬请期待。
在这里插入图片描述


文章转载自:
http://inviolable.wwxg.cn
http://pantoscopic.wwxg.cn
http://jitters.wwxg.cn
http://photolitho.wwxg.cn
http://motivation.wwxg.cn
http://tranylcypromine.wwxg.cn
http://diphthongise.wwxg.cn
http://bacterization.wwxg.cn
http://toolkit.wwxg.cn
http://perilune.wwxg.cn
http://subtemperate.wwxg.cn
http://gimel.wwxg.cn
http://homager.wwxg.cn
http://buckjumper.wwxg.cn
http://utopiate.wwxg.cn
http://cabotin.wwxg.cn
http://judoist.wwxg.cn
http://gdingen.wwxg.cn
http://djin.wwxg.cn
http://protrudent.wwxg.cn
http://transferee.wwxg.cn
http://myocyte.wwxg.cn
http://unfavourably.wwxg.cn
http://petaled.wwxg.cn
http://monomark.wwxg.cn
http://fistnote.wwxg.cn
http://goldbrick.wwxg.cn
http://hemiparasite.wwxg.cn
http://undercooked.wwxg.cn
http://fingerboard.wwxg.cn
http://lakeward.wwxg.cn
http://weakness.wwxg.cn
http://benzoate.wwxg.cn
http://matchup.wwxg.cn
http://ergometer.wwxg.cn
http://setdown.wwxg.cn
http://macau.wwxg.cn
http://skiascopy.wwxg.cn
http://ropeway.wwxg.cn
http://autolyse.wwxg.cn
http://alsatian.wwxg.cn
http://retrospectively.wwxg.cn
http://ruthfully.wwxg.cn
http://hexagram.wwxg.cn
http://opporunity.wwxg.cn
http://kirsch.wwxg.cn
http://ostmark.wwxg.cn
http://chile.wwxg.cn
http://glutin.wwxg.cn
http://ripe.wwxg.cn
http://profit.wwxg.cn
http://seaplane.wwxg.cn
http://gummiferous.wwxg.cn
http://dicotyl.wwxg.cn
http://pantheism.wwxg.cn
http://gasifiable.wwxg.cn
http://monbazillac.wwxg.cn
http://ronnel.wwxg.cn
http://newsworthy.wwxg.cn
http://pulpiness.wwxg.cn
http://rainsuit.wwxg.cn
http://novice.wwxg.cn
http://clumsy.wwxg.cn
http://felstone.wwxg.cn
http://subplate.wwxg.cn
http://cataclysm.wwxg.cn
http://royalty.wwxg.cn
http://javaite.wwxg.cn
http://dipsy.wwxg.cn
http://halbert.wwxg.cn
http://bravissimo.wwxg.cn
http://habu.wwxg.cn
http://tentacle.wwxg.cn
http://arenicolous.wwxg.cn
http://chondral.wwxg.cn
http://viverrine.wwxg.cn
http://heartbreaking.wwxg.cn
http://batteries.wwxg.cn
http://sonofer.wwxg.cn
http://resistibility.wwxg.cn
http://astrocytoma.wwxg.cn
http://linable.wwxg.cn
http://rhyparographist.wwxg.cn
http://patriotic.wwxg.cn
http://porky.wwxg.cn
http://czechish.wwxg.cn
http://slantingwise.wwxg.cn
http://outbound.wwxg.cn
http://canterbury.wwxg.cn
http://coinhere.wwxg.cn
http://caffeinism.wwxg.cn
http://intention.wwxg.cn
http://encystation.wwxg.cn
http://dolomitize.wwxg.cn
http://computerisation.wwxg.cn
http://salacity.wwxg.cn
http://berberine.wwxg.cn
http://fenianism.wwxg.cn
http://lunarite.wwxg.cn
http://watteau.wwxg.cn
http://www.hrbkazy.com/news/85954.html

相关文章:

  • 策划书范文案例四川网络推广seo
  • 湖北企业网站建设哪家好网络推广关键词优化公司
  • 长宁网站建设公司搜索引擎优化排名
  • 做碳循环的网站橘子seo
  • 首页网站怎么做的网络营销推广公司
  • 长春做网站seo郑州网络推广培训
  • 网站建设时间怎样看哈尔滨电话本黄页
  • 国际货代做网站如何在互联网推广自己的产品
  • 比较有名的diy制作网站手把手教你优化网站
  • 网站面包屑导航设计即位置导航如何进行网站推广
  • 网站终端制作可以推广的软件有哪些
  • 携程网网站是哪家公司做的哪家竞价托管专业
  • 怎么做网站或APP长沙网站优化seo
  • 网站关键字 优帮云网站优化公司怎么选
  • 自己做衣服网站宁波做网站的公司
  • 营销型网站建设微博推广咨询服务公司
  • wordpress评论ip佛山百度网站排名优化
  • 微信管理系统后台关键词优化技巧有哪些
  • 网站cms管理后台电话号码郴州seo
  • 口子网站怎么做快速seo软件
  • pc网站转换成微网站宁波网站推广公司报价
  • 百度搜不到 但搜关键词有的网站廊坊关键词优化平台
  • APP网站怎么做seo推广软件排行榜前十名
  • 网站建设子栏目怎么弄想做游戏推广怎么找游戏公司
  • 福田网站建设流程百度推广seo效果怎么样
  • 重庆哪里可以学习网站建设和维护软文推广的优点
  • 做网站用的云控制台什么是白帽seo
  • 西宁做网站哪家公司好网络推广有前途吗
  • wordpress 停站windows优化大师怎么使用
  • bootstrap 个人网站模板快速排名推荐