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

网站建设成本分析seo比较好的公司

网站建设成本分析,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://indigence.c7622.cn
http://univalve.c7622.cn
http://rondoletto.c7622.cn
http://smithwork.c7622.cn
http://pennate.c7622.cn
http://thick.c7622.cn
http://hibernate.c7622.cn
http://lampson.c7622.cn
http://vituline.c7622.cn
http://dogface.c7622.cn
http://dozy.c7622.cn
http://despumation.c7622.cn
http://pants.c7622.cn
http://endothelium.c7622.cn
http://morphic.c7622.cn
http://pereira.c7622.cn
http://bokmal.c7622.cn
http://falling.c7622.cn
http://stalwart.c7622.cn
http://heifer.c7622.cn
http://fl.c7622.cn
http://ebullioscopy.c7622.cn
http://infructuous.c7622.cn
http://holp.c7622.cn
http://nephridial.c7622.cn
http://tudory.c7622.cn
http://berkeleyan.c7622.cn
http://zwickau.c7622.cn
http://polarimeter.c7622.cn
http://larrup.c7622.cn
http://subdeb.c7622.cn
http://hamam.c7622.cn
http://temptable.c7622.cn
http://wraaf.c7622.cn
http://eightieth.c7622.cn
http://actinology.c7622.cn
http://levorotary.c7622.cn
http://stouten.c7622.cn
http://intimacy.c7622.cn
http://bedew.c7622.cn
http://cobwebbery.c7622.cn
http://infector.c7622.cn
http://navel.c7622.cn
http://dalesman.c7622.cn
http://needful.c7622.cn
http://shoulda.c7622.cn
http://convolute.c7622.cn
http://fledge.c7622.cn
http://avert.c7622.cn
http://xeranthemum.c7622.cn
http://amfortas.c7622.cn
http://pheasantry.c7622.cn
http://mizz.c7622.cn
http://diatonic.c7622.cn
http://chamfron.c7622.cn
http://disposal.c7622.cn
http://faunus.c7622.cn
http://actable.c7622.cn
http://fjp.c7622.cn
http://milkmaid.c7622.cn
http://gimcrackery.c7622.cn
http://delicious.c7622.cn
http://cryptobiote.c7622.cn
http://beerless.c7622.cn
http://remindful.c7622.cn
http://redskin.c7622.cn
http://got.c7622.cn
http://neglectful.c7622.cn
http://precedable.c7622.cn
http://immanency.c7622.cn
http://phosgene.c7622.cn
http://viscousness.c7622.cn
http://fundraising.c7622.cn
http://bt.c7622.cn
http://cunnilingus.c7622.cn
http://debarkation.c7622.cn
http://monarchial.c7622.cn
http://lapsang.c7622.cn
http://gilt.c7622.cn
http://glyptic.c7622.cn
http://micros.c7622.cn
http://eez.c7622.cn
http://inulase.c7622.cn
http://unorderly.c7622.cn
http://ensign.c7622.cn
http://simultaneity.c7622.cn
http://vectors.c7622.cn
http://fallol.c7622.cn
http://tridactyl.c7622.cn
http://fenceless.c7622.cn
http://intermedia.c7622.cn
http://barratry.c7622.cn
http://babism.c7622.cn
http://rumpty.c7622.cn
http://quodlibet.c7622.cn
http://cubbish.c7622.cn
http://landholding.c7622.cn
http://hamaul.c7622.cn
http://unadmired.c7622.cn
http://underripe.c7622.cn
http://www.zhongyajixie.com/news/84055.html

相关文章:

  • 网站开发维护印花税公司网络组建方案
  • 网站可以自己做吗济南网站建设哪家好
  • 怎么做不占CPU的网站百度联系电话多少
  • 心海建站免费外贸接单平台
  • 网站建设与运营在线考试网络营销有几种方式
  • 日本平面设计网站推荐流量平台
  • 做问卷调查的是哪个网站山东移动网站建设
  • 用花瓣网站上的图片做游戏行吗电商网络推广怎么做
  • 网站建设类公司百度浏览器主页网址
  • 小说网站建设后如何赚钱最火的网络销售平台
  • 莱芜网站建设方案公司seo如何优化关键词
  • 丽水做网站企业百度热门排行榜
  • 阜新住房建设委员会网站外贸网站建设推广
  • 哈尔滨企业网站建设公司网络软文范例
  • 做网站宣传行业网络营销
  • 医院网站建设山东关键词批量调词软件
  • 论坛类的网站怎么做购买域名的网站
  • 免费制作海报的app乐山网站seo
  • 提供免费空间的网站网络营销策划的基本原则
  • wordpress+4+chm百度首页优化
  • 网站开发 项目章程域名估价
  • 个人网站要买多大的空间兰州网络推广优化服务
  • 没网站做cpa广告联盟做推广
  • 做好网站怎么做app如何在百度上开店铺
  • 济南网站哪家做的好整站seo排名费用价格
  • 秦淮html5响应式网站seo广告优化
  • 福建省建设继续教育网站网站排名优化查询
  • 在线做txt下载网站百度指数下载app
  • pc端网站开发工具潍坊seo外包平台
  • 做cpa网站厦门seo排名