中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

做設(shè)計比較好的網(wǎng)站網(wǎng)站推廣排名服務(wù)

做設(shè)計比較好的網(wǎng)站,網(wǎng)站推廣排名服務(wù),模具外貿(mào)營銷網(wǎng)站如何做,css模板網(wǎng)站目錄 11.4 SpringAMQP 11.4.2 Work Queue工作隊列 11.4.3 發(fā)布訂閱模型 11.4.4 FanoutExchange(廣播交換機(jī)) 11.4.5 DirectExchange(路由模式交換機(jī)) 11.4.6 TopicExchange 11.5 消息轉(zhuǎn)換器 11.4 SpringAMQP 父工程引入AMQP依賴 <!--AMQP依賴&#xff0c;包含RabbitMQ…

目錄

11.4 SpringAMQP

11.4.2 Work Queue工作隊列

11.4.3 發(fā)布訂閱模型

11.4.4 FanoutExchange(廣播交換機(jī))

11.4.5 DirectExchange(路由模式交換機(jī))

11.4.6 TopicExchange

11.5 消息轉(zhuǎn)換器


11.4 SpringAMQP

父工程引入AMQP依賴

  <!--AMQP依賴,包含RabbitMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>

編寫測試方法

yml配置文件中編寫配置

  spring:rabbitmq:host: 192.168.142.130 ? # rabbitmq的ip地址port: 5672  # 端口username: xxxxxpassword: xxxxxxxvirtual-host: /

發(fā)消息測試

  @SpringBootTestpublic class AMQPTest {?@Autowiredprivate RabbitTemplate rabbitTemplate;?@Testpublic void testSendMessage2SimpleQueue(){String queueName = "simple.queue";String message = "hello,spring amqp";rabbitTemplate.convertAndSend(queueName,message);}}

在consumer中編寫消費(fèi)邏輯,監(jiān)聽simple.queue

配置文件配置 :

  spring:rabbitmq:host: 192.168.142.129 ? # rabbitmq的ip地址port: 5672  # 端口username: xxxxxpassword: xxxxxvirtual-host: /

編寫監(jiān)聽類

  @Componentpublic class SpringRabbitListener {@RabbitListener(queues = "simple.queue")public void ListenSimpleQueue(String msg){System.out.println("消費(fèi)者接收到simple.queue的消息 : " + msg);}}

啟動主啟動類,控制臺可看到輸出的監(jiān)聽到的消息

消息一旦被消費(fèi),就會從隊列中刪除,沒有回收機(jī)制

11.4.2 Work Queue工作隊列

publisher代碼

  @Testpublic void testSendMessage2WorkQueue() throws InterruptedException {String queueName = "simple.queue";String message = "hello,spring amqp__";for(int i = 1 ; i <= 50 ; i ++){rabbitTemplate.convertAndSend(queueName,message + i); ? Thread.sleep(20);}}

consumer接收消息

  // 消費(fèi)者1@RabbitListener(queues = "simple.queue")public void ListenWork1Queue(String msg) throws InterruptedException {System.out.println("消費(fèi)者1接收到simple.queue的消息 : " + msg + LocalTime.now());Thread.sleep(20);}?// 消費(fèi)者2@RabbitListener(queues = "simple.queue")public void ListenWork2Queue(String msg) throws InterruptedException {System.err.println("消費(fèi)者2接收到simple.queue的消息 : " + msg + LocalTime.now());Thread.sleep(200);}

消息預(yù)取機(jī)制使得兩者平均分配消息 不符預(yù)期

配置文件中 :

處理預(yù)取值

  spring:rabbitmq:host: 192.168.142.129 ? # rabbitmq的ip地址port: 5672 ?# 端口username: xxxxxxpassword: xxxxxxxvirtual-host: /listener:simple:prefetch: 1 ? ?# 每次只能獲取一條消息 ,處理完成才能獲取下一個信息

11.4.3 發(fā)布訂閱模型

11.4.4 FanoutExchange(廣播交換機(jī))

步驟一 : 聲明交換機(jī),隊列 , 并綁定隊列和交換機(jī)

在consumer中編寫配置類

  @Configurationpublic class FanoutConfig {// 聲明交換機(jī)@Beanpublic FanoutExchange fanoutExchange(){return new FanoutExchange("xinbo.fanout");}?// 聲明隊列1@Beanpublic Queue fanoutQueue1(){return new Queue("fanout.queue1");}?// 綁定隊列1到交換機(jī)@Beanpublic Binding fanoutBindind(Queue fanoutQueue1,FanoutExchange fanoutExchange){return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);}?// 聲明隊列2@Beanpublic Queue fanoutQueue2(){return new Queue("fanout.queue2");}?// 綁定隊列2到交換機(jī)@Beanpublic Binding fanoutBindind2(Queue fanoutQueue2,FanoutExchange fanoutExchange){return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);}}

消息監(jiān)聽 :

  @Componentpublic class SpringRabbitListener {?// 消費(fèi)者1@RabbitListener(queues = "fanout.queue1")public void ListenWork1Queue(String msg) throws InterruptedException {System.out.println("消費(fèi)者1接收到fanout.queue1的消息 : " + msg + LocalTime.now());Thread.sleep(20);}?// 消費(fèi)者2@RabbitListener(queues = "fanout.queue2")public void ListenWork2Queue(String msg) throws InterruptedException {System.err.println("消費(fèi)者2接收到fanout.queue2的消息 : " + msg + LocalTime.now());Thread.sleep(200);}}

消息發(fā)送 :

  @Testpublic void testSendFanoutExchange(){String exchangeName = "xinbo.fanout"; ? ? ? ? ? ? ? // 交換機(jī)名稱String message = "hello,everyone";rabbitTemplate.convertAndSend(exchangeName,null,message);}

11.4.5 DirectExchange(路由模式交換機(jī))

利用@RabbitListener聲明Exchange Queue RoutingKey

SpirngRabbitListener中

  @Componentpublic class SpringRabbitListener {?@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue1"),exchange = @Exchange(name = "xinbo.direct",type = ExchangeTypes.DIRECT),key = {"red","blue"}))public void ListenDirectQueue1(String msg) throws InterruptedException {System.out.println("消費(fèi)者接收到direct.queue1的消息 : " + msg + LocalTime.now());Thread.sleep(20);}?@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue2"),exchange = @Exchange(name = "xinbo.direct",type = ExchangeTypes.DIRECT),key = {"red","yellow"}))public void ListenDirectQueue2(String msg) throws InterruptedException {System.out.println("消費(fèi)者接收到direct.queue2的消息 : " + msg + LocalTime.now());Thread.sleep(20);}?}

發(fā)送消息測試 :

  @Testpublic void testSendDirectExchange(){// 交換機(jī)名稱String exchangeName = "xinbo.direct";String message = "hello,blue";rabbitTemplate.convertAndSend(exchangeName,"blue",message);}

11.4.6 TopicExchange

綁定隊列和交換機(jī)的關(guān)系 :

  @Componentpublic class SpringRabbitListener {@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "topic.queue1"),exchange = @Exchange(name="xinbo.topic",type = ExchangeTypes.TOPIC),key = "china.#"))public void ListenTopicQueue1(String msg){System.out.println("消費(fèi)者接收到topic.queue1的消息 : " + msg + LocalTime.now());}?@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "topic.queue2"),exchange = @Exchange(name="xinbo.topic",type = ExchangeTypes.TOPIC),key = "#.news"))public void ListenTopicQueue2(String msg){System.out.println("消費(fèi)者接收到topic.queue2的消息 : " + msg + LocalTime.now());}?}

發(fā)送消息 :

  @Testpublic void testSendTopicExchange(){// 交換機(jī)名稱String exchangeName = "xinbo.topic";String message = "中國發(fā)生了xxxxx";rabbitTemplate.convertAndSend(exchangeName,"china.news",message);}

11.5 消息轉(zhuǎn)換器

發(fā)送和接受json類型的消息

添加依賴 :

  <dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-xml</artifactId></dependency>

在配置類中

  @Beanpublic MessageConverter messageCondition(){return new Jackson2JsonMessageConverter();}

接收消息 :

引依賴 :同上

在Listener中 :

  @RabbitListener(queues = "object.queue")public void ListenObjectQueue(Map<String,Object> msg){System.out.println(msg);}
http://www.risenshineclean.com/news/27677.html

相關(guān)文章:

  • 網(wǎng)站設(shè)計要求 優(yōu)幫云營銷推廣方案包括哪些內(nèi)容
  • 江門網(wǎng)站制作維護(hù)app下載推廣平臺
  • 企業(yè)建設(shè)網(wǎng)站的空間有哪些搜狗收錄提交入口
  • 網(wǎng)站群信息管理系統(tǒng)北京網(wǎng)站優(yōu)化專家
  • 主題公園wordpressseo線下培訓(xùn)課程
  • 學(xué)計算機(jī)網(wǎng)站建設(shè)seo排名優(yōu)化培訓(xùn)怎樣
  • 西寧網(wǎng)站seo外包百度安裝到桌面
  • 網(wǎng)站開發(fā)可以做什么seo 優(yōu)化公司
  • 創(chuàng)建小型網(wǎng)站的步驟太原網(wǎng)站關(guān)鍵詞推廣
  • 南通高端網(wǎng)站建設(shè)公司關(guān)鍵詞搜索技巧
  • .net 網(wǎng)站制作百度app怎么找人工客服
  • 互聯(lián)網(wǎng)技術(shù)對人力資源管理的影響有哪些seo專員的工作內(nèi)容
  • 網(wǎng)站鏡像代理怎么做百度廣告聯(lián)盟
  • 上海市建設(shè)安全協(xié)會網(wǎng)站j搜索引擎優(yōu)化關(guān)鍵字
  • wordpress ip 訪問安卓優(yōu)化大師手機(jī)版下載
  • 怎么用代碼做網(wǎng)站查詢網(wǎng)站域名
  • 網(wǎng)站域名哪些后綴更好石家莊谷歌seo
  • 網(wǎng)站建設(shè)模板企業(yè)門戶網(wǎng)站模板
  • 盲盒小程序搭建網(wǎng)站優(yōu)化平臺
  • wordpress htwo下載地址網(wǎng)站排名優(yōu)化
  • 商務(wù)型企業(yè)網(wǎng)站建設(shè)開魯視頻
  • 在阿里巴巴國際網(wǎng)站上需要怎么做鄭州搜索引擎優(yōu)化公司
  • 四川做網(wǎng)站價格網(wǎng)站怎么優(yōu)化搜索
  • 東方財富網(wǎng)官方網(wǎng)站首頁關(guān)鍵詞熱度
  • 可做分析圖的地圖網(wǎng)站百度搜索
  • 東莞市政府網(wǎng)站官網(wǎng)百度指數(shù)app下載
  • 香港購物網(wǎng)站優(yōu)化大師專業(yè)版
  • 珠海工程建設(shè)信息網(wǎng)站快速網(wǎng)站輕松排名
  • 做二手網(wǎng)站有哪些問題愛站工具包的主要功能
  • 西安網(wǎng)站建設(shè)公搜索廣告是什么