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

网站建设成本分析百度seo策略

网站建设成本分析,百度seo策略,网站建设期任务及总结,用相片制作视频的软件上文着重介绍RabbitMQ 七种工作模式介绍RabbitMQ 七种工作模式介绍_rabbitmq 工作模式-CSDN博客 本篇讲解如何在Spring环境下进⾏RabbitMQ的开发.(只演⽰部分常⽤的⼯作模式) 目录 引⼊依赖 一.工作队列模式 二.Publish/Subscribe(发布订阅模式) …

上文着重介绍RabbitMQ 七种工作模式介绍RabbitMQ 七种工作模式介绍_rabbitmq 工作模式-CSDN博客

本篇讲解如何在Spring环境下进⾏RabbitMQ的开发.(只演⽰部分常⽤的⼯作模式)

目录

引⼊依赖 

一.工作队列模式

二.Publish/Subscribe(发布订阅模式)

三.Routing(路由模式)

四.Topics(通配符模式)


引⼊依赖 

pom.xml 可以导入依赖

<!--Spring MVC相关依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--RabbitMQ相关依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

或者创建项目时候勾选相应的选项

进入项目第一步先进行分类 三层架构 

进行配置相关rabbitmq属性 


一.工作队列模式

生产者:

@RestController
@RequestMapping("/produce")
public class ProducerController {@Autowiredprivate RabbitTemplate rabbitTemplate;@RequestMapping("/work")public String work() {rabbitTemplate.convertAndSend("", Constans.WORK_QUEUE,"hello spring amqp:work...");return "发送成功";}
}

convertAndSendRabbitTemplate类提供的一个重要方法,用于将消息发送到 RabbitMQ 的指定队列中 。

  • 第一个参数"":在这里通常表示交换机(Exchange)的名称为空字符串。
  • 第二个参数Constans.WORK_QUEUE
  • 第三个参数"hello spring amqp:work...":这就是要发送的实际消息内容

 通过网页进行测试是否发送成功

从rabbitmq上可以看出已经发送成功到队列,等待消费者进行消费 

 消费者:

@Component
public class WorkListener {@RabbitListener(queues = Constants.WORK_QUEUE)public void queueListener1(Message message) {System.out.println("listener 1 ["+Constants.WORK_QUEUE+"] 接收到消息:" +message);}@RabbitListener(queues = Constants.WORK_QUEUE)public void queueListener2(Message message) {System.out.println("listener 2 ["+Constants.WORK_QUEUE+"] 接收到消息:" +message);}
}

@RabbitListener 是Spring框架中⽤于监听RabbitMQ队列的注解,通过使⽤这个注解,可以定义⼀个⽅法,以便从RabbitMQ队列中接收消息.该注解⽀持多种参数类型,这些参数类型代表了从RabbitMQ接收到的消息和相关信息.

@Component
public class WorkListener {@RabbitListener(queues = Constants.WORK_QUEUE)public void queueListener1(String message) {System.out.println("listener 1 ["+Constants.WORK_QUEUE+"] 接收到消息:" +message);}@RabbitListener(queues = Constants.WORK_QUEUE)public void queueListener2(String message) {System.out.println("listener 2 ["+Constants.WORK_QUEUE+"] 接收到消息:" +message);}
}

1. String 返回消息的内容
2. Message ( org.springframework.amqp.core.Message ):SpringAMQP的
Message 类,返回原始的消息体以及消息的属性,如消息ID,内容,队列信息等.


 二.Publish/Subscribe(发布订阅模式)

声明队列,交换机,绑定队列和交换机

    //发布订阅模式public static final String FANOUT_QUEUE1 = "fanout.queue1";public static final String FANOUT_QUEUE2 = "fanout.queue2";public static final String FANOUT_EXCHANGE = "fanout.exchange";
    //发布订阅模式@Bean("fanoutQueue1")public Queue fanoutQueue1() {return QueueBuilder.durable(Constants.FANOUT_QUEUE1).build();}@Bean("fanoutQueue2")public Queue fanoutQueue2() {return QueueBuilder.durable(Constants.FANOUT_QUEUE2).build();}@Bean("fanoutExchange")public FanoutExchange fanoutExchange() {return ExchangeBuilder.fanoutExchange(Constants.FANOUT_EXCHANGE).durable(true).build();}@Bean("fanoutQueueBinding1")public Binding fanoutQueueBinding1(@Qualifier("fanoutExchange") FanoutExchange fanoutExchange, @Qualifier("fanoutQueue1") Queue queue){return BindingBuilder.bind(queue).to(fanoutExchange);}@Bean("fanoutQueueBinding2")public Binding fanoutQueueBinding2(@Qualifier("fanoutExchange") FanoutExchange fanoutExchange, @Qualifier("fanoutQueue2") Queue queue){return BindingBuilder.bind(queue).to(fanoutExchange);}

生产者:

    @RequestMapping("/fanout")public String fanout(){rabbitTemplate.convertAndSend(Constants.FANOUT_EXCHANGE,"", "hello spring amqp:fanout...");return "发送成功";}

消费者:

@Component
public class FanoutListener {@RabbitListener(queues = Constants.FANOUT_QUEUE1)public void queueListener1(String message) {System.out.println("listener 1 ["+Constants.FANOUT_QUEUE1+"] 接收到消息:" +message);}@RabbitListener(queues = Constants.FANOUT_QUEUE2)public void queueListener2(String message) {System.out.println("listener 2 ["+Constants.FANOUT_QUEUE2+"] 接收到消息:" +message);}
}


三.Routing(路由模式)

 

声明队列,交换机,绑定队列和交换机 

    //路由模式public static final String DIRECT_QUEUE1 = "direct.queue1";public static final String DIRECT_QUEUE2 = "direct.queue2";public static final String DIRECT_EXCHANGE = "direct.exchange";
    //路由模式@Bean("directQueue1")public Queue directQueue1() {return QueueBuilder.durable(Constants.DIRECT_QUEUE1).build();}@Bean("directQueue2")public Queue directQueue2() {return QueueBuilder.durable(Constants.DIRECT_QUEUE2).build();}@Bean("directExchange")public DirectExchange directExchange() {return ExchangeBuilder.directExchange(Constants.DIRECT_EXCHANGE).durable(true).build();}@Bean("directQueueBinding1")public Binding directQueueBinding1(@Qualifier("directExchange") DirectExchange directExchange, @Qualifier("directQueue1") Queue queue){return BindingBuilder.bind(queue).to(directExchange).with("orange");}@Bean("directQueueBinding2")public Binding directQueueBinding2(@Qualifier("directExchange") DirectExchange directExchange, @Qualifier("directQueue2") Queue queue){return BindingBuilder.bind(queue).to(directExchange).with("black");}@Bean("directQueueBinding3")public Binding directQueueBinding3(@Qualifier("directExchange") DirectExchange directExchange, @Qualifier("directQueue2") Queue queue){return BindingBuilder.bind(queue).to(directExchange).with("orange");}

 


生产者:

    @RequestMapping("/direct/{rountingKey}")public String direct(@PathVariable("routingKey") String rountingKey){rabbitTemplate.convertAndSend(Constants.DIRECT_EXCHANGE,"", "hello spring amqp:direct, my routing key is "+rountingKey);return "发送成功";}

@PathVariable :用于从请求的 URL 路径中提取参数值。

  • 当有一个请求访问/direct/后面跟着某个具体的值(例如/direct/key1)时,@PathVariable("routingKey") String rountingKey会将key1提取出来,并赋值给rountingKey变量。


消费者:

@Component
public class DirectListener {@RabbitListener(queues = Constants.DIRECT_QUEUE1)public void queueListener1(String message) {System.out.println("listener 1 ["+Constants.DIRECT_QUEUE1+"] 接收到消息:" +message);}@RabbitListener(queues = Constants.DIRECT_QUEUE2)public void queueListener2(String message) {System.out.println("listener 2 ["+Constants.DIRECT_QUEUE2+"] 接收到消息:" +message);}
}


四.Topics(通配符模式)

 

. 代表一个单词

# 代码多个单词 

    //通配符模式public static final String TOPIC_QUEUE1 = "topics_queue1";public static final String TOPIC_QUEUE2 = "topics_queue2";public static final String TOPIC_EXCHANGE = "topics_exchange";
    //通配符模式@Bean("topicQueue1")public Queue topicQueue1(){return QueueBuilder.durable(Constants.TOPIC_QUEUE1).build();}@Bean("topicQueue2")public Queue topicQueue2(){return QueueBuilder.durable(Constants.TOPIC_QUEUE2).build();}@Bean("topicExchange")public TopicExchange topicExchange(){return ExchangeBuilder.topicExchange(Constants.TOPIC_EXCHANGE).durable(true).build();}@Bean("topicQueueBinding1")public Binding topicQueueBinding1(@Qualifier("topicExchange") TopicExchange topicExchange, @Qualifier("topicQueue1") Queue queue){return BindingBuilder.bind(queue).to(topicExchange).with("*.orange.*");}@Bean("topicQueueBinding2")public Binding topicQueueBinding2(@Qualifier("topicExchange") TopicExchange topicExchange, @Qualifier("topicQueue2") Queue queue){return BindingBuilder.bind(queue).to(topicExchange).with("*.*.rabbit");}@Bean("topicQueueBinding3")public Binding topicQueueBinding3(@Qualifier("topicExchange") TopicExchange topicExchange, @Qualifier("topicQueue2") Queue queue){return BindingBuilder.bind(queue).to(topicExchange).with("lazy.#");}


生产者

    @RequestMapping("/topic/{routingKey}")public String topic(@PathVariable("routingKey") String routingKey){rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE,routingKey, "hello spring amqp:topic, my routing key is "+routingKey);return "发送成功";}


消费者

@Component
public class TopicListener {@RabbitListener(queues = Constants.TOPIC_QUEUE1)public void queueListener1(String message) {System.out.println("listener 1 ["+Constants.TOPIC_QUEUE1+"] 接收到消息:" +message);}@RabbitListener(queues = Constants.TOPIC_QUEUE2)public void queueListener2(String message) {System.out.println("listener 2 ["+Constants.TOPIC_QUEUE2+"] 接收到消息:" +message);}
}


结语: 写博客不仅仅是为了分享学习经历,同时这也有利于我巩固知识点,总结该知识点,由于作者水平有限,对文章有任何问题的还请指出,接受大家的批评,让我改进。同时也希望读者们不吝啬你们的点赞+收藏+关注,你们的鼓励是我创作的最大动力!  


文章转载自:
http://nary.c7512.cn
http://springlet.c7512.cn
http://sweater.c7512.cn
http://municipalist.c7512.cn
http://eyepit.c7512.cn
http://doctrinairism.c7512.cn
http://recoilless.c7512.cn
http://arghan.c7512.cn
http://reroll.c7512.cn
http://hemp.c7512.cn
http://spatzle.c7512.cn
http://claustrophobe.c7512.cn
http://kilowatt.c7512.cn
http://minshan.c7512.cn
http://doer.c7512.cn
http://phonograph.c7512.cn
http://succubi.c7512.cn
http://unminished.c7512.cn
http://cichlid.c7512.cn
http://diastole.c7512.cn
http://extramural.c7512.cn
http://honeylipped.c7512.cn
http://defocus.c7512.cn
http://definable.c7512.cn
http://almoner.c7512.cn
http://bigaroon.c7512.cn
http://paperback.c7512.cn
http://na.c7512.cn
http://yomp.c7512.cn
http://corvina.c7512.cn
http://sheerly.c7512.cn
http://apoferritin.c7512.cn
http://accidental.c7512.cn
http://monorail.c7512.cn
http://dowry.c7512.cn
http://gunfire.c7512.cn
http://haemorrhage.c7512.cn
http://capriccioso.c7512.cn
http://immodesty.c7512.cn
http://entopic.c7512.cn
http://frontier.c7512.cn
http://gulfy.c7512.cn
http://heterecious.c7512.cn
http://lacrimatory.c7512.cn
http://bagatelle.c7512.cn
http://certified.c7512.cn
http://oscilloscope.c7512.cn
http://hospitalism.c7512.cn
http://cryptorchid.c7512.cn
http://gage.c7512.cn
http://untomb.c7512.cn
http://kudo.c7512.cn
http://episematic.c7512.cn
http://put.c7512.cn
http://diverting.c7512.cn
http://euphrates.c7512.cn
http://ambatch.c7512.cn
http://unreached.c7512.cn
http://seafood.c7512.cn
http://holocaine.c7512.cn
http://overdrop.c7512.cn
http://zoometry.c7512.cn
http://safeguard.c7512.cn
http://eulachon.c7512.cn
http://russia.c7512.cn
http://gila.c7512.cn
http://inseverable.c7512.cn
http://alamode.c7512.cn
http://factorize.c7512.cn
http://endopleura.c7512.cn
http://subcollege.c7512.cn
http://curtly.c7512.cn
http://topectomize.c7512.cn
http://sinapin.c7512.cn
http://achordate.c7512.cn
http://gaping.c7512.cn
http://consubstantiate.c7512.cn
http://jettison.c7512.cn
http://chiropteran.c7512.cn
http://fountful.c7512.cn
http://swill.c7512.cn
http://powerboat.c7512.cn
http://parochial.c7512.cn
http://reed.c7512.cn
http://creolization.c7512.cn
http://polarize.c7512.cn
http://comtist.c7512.cn
http://neorealist.c7512.cn
http://thiobacillus.c7512.cn
http://churching.c7512.cn
http://redress.c7512.cn
http://ictinus.c7512.cn
http://overspread.c7512.cn
http://pedochemical.c7512.cn
http://qse.c7512.cn
http://anthracosis.c7512.cn
http://unaffectionate.c7512.cn
http://glutethimide.c7512.cn
http://frunze.c7512.cn
http://hydrokinetics.c7512.cn
http://www.zhongyajixie.com/news/72080.html

相关文章:

  • 南昌网站搭建公司 赣ICP百度推广开户联系方式
  • 海外站推广微信小程序平台官网
  • 劳务网站怎样做北京已感染上千万人
  • 开放一个网站多少钱seo流量排行榜神器
  • 太仓网站开发上海优化公司
  • 模板手机网站建设百度人工电话多少号
  • 湛江全套网站建设费用宣传广告怎么做吸引人
  • 渝叶购零售客户电商网站站长之家素材
  • 湖南网站设计制作免费域名注册网站
  • 三站合一的网站怎么做教程上海seo
  • 南充做网站略奥网络百度托管公司
  • 做网站和做网店哪个好游戏推广员到底犯不犯法
  • 泉州市网站api建设windows优化大师官方免费
  • 找哪个网站做摩配怎么样引流加微信
  • 做排行榜的网站知乎搜索引擎大全排行
  • 行业网站方案百度seo优化技术
  • 电商出口营销要多少钱windows优化大师要钱
  • 网站设计需要的元素广告外链购买交易平台
  • 室内联盟官网短视频seo营销
  • 企业网站建设合同深圳网络推广服务是什么
  • 什么网站容易做网站设计规划
  • 广安建设局网站seo的中文意思是什么
  • 中国建设委员会官方网站百度app下载官方
  • 南京网站制作公司有哪些海外营销
  • 郑州网站建设网站制作东莞网络营销
  • 广西南宁b2b网站建设营销型网站建设目标
  • 郓城网站建设旅游企业seo官网分析报告
  • 最好的响应式网站免费可用的网站源码
  • 网站如何注册微信公众平台 类型360搜索首页
  • 深圳网站建设招聘kol营销模式