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

asp.net 当前网站好省推广100种方法

asp.net 当前网站,好省推广100种方法,企业网站管理系统设置,建设导航网站文章目录 pomyml生产者消费者 Topic类型的Exchange与Direct相比,都是可以根据RoutingKey把消息路由到不同的队列。只不过Topic类型Exchange可以让队列在绑定Routing key 的时候使用通配符! Routingkey 一般都是有一个或多个单词组成,多个单词…

文章目录

  • pom
  • yml
  • 生产者
  • 消费者


在这里插入图片描述

Topic类型的ExchangeDirect相比,都是可以根据RoutingKey把消息路由到不同的队列。只不过Topic类型Exchange可以让队列在绑定Routing key 的时候使用通配符!

Routingkey 一般都是有一个或多个单词组成,多个单词之间以”.”分割,例如: snow.com

通配符规则:

#:匹配一个或多个词

*:匹配不多不少恰好1个词

举例:

snow.#:能够匹配snow.com.cn 或者 snow.com

snow.*:只能匹配snow.com

如下图:
在这里插入图片描述
解释:

  • Queue1:绑定的是china.# ,因此凡是以 china.开头的routing key 都会被匹配到。包括china.news和china.weather
  • Queue2:绑定的是#.news ,因此凡是以 .news结尾的 routing key 都会被匹配。包括china.news和japan.news

案例需求:
实现思路如下:

  1. 并利用 @RabbitListener 声明 Exchange、Queue、RoutingKey
  2. 在 consumer 服务中,编写两个消费者方法,分别监听 business.test.topic.queue1business.test.topic.queue2
  3. 在 publisher 中编写测试方法,向business.test.topic发送消息

pom

    <dependencies><!--RabbitMQ 依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.47</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies>

yml

server:port: 8080
spring:rabbitmq:host: **.***.**.***port: 5672username: ****password: ****

生产者

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @author: Snow* @date: 2023/1/6* *************************************************** 修改记录(时间--修改人--修改说明):*/
@RestController
@RequestMapping("/topic")
public class SendController {@Autowiredprivate RabbitTemplate rabbitTemplate;@GetMapping("/send/{message}")public void send(@PathVariable("message") String message){// 交换机名称String exchangeName = "business.test.topic";// 发送消息if(message.contains("china") && message.contains("news")){rabbitTemplate.convertAndSend(exchangeName, "china.news", message);return;}if(message.contains("china")){rabbitTemplate.convertAndSend(exchangeName, "china.lala", message);return;}if(message.contains("news")){rabbitTemplate.convertAndSend(exchangeName, "lalla.news", message);return;}}}

消费者

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** @author: Snow* @date: 2023/1/6* *************************************************** 修改记录(时间--修改人--修改说明):*/
@Component
public class Consumer {@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "business.test.topic.queue1"),exchange = @Exchange(name = "business.test.topic", type = ExchangeTypes.TOPIC),key = "china.#"))public void listenTopicQueue1(String msg){System.out.println("消费者接收到topic.queue1的消息:【" + msg + "】");}@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "business.test.topic.queue2"),exchange = @Exchange(name = "business.test.topic", type = ExchangeTypes.TOPIC),key = "#.news"))public void listenTopicQueue2(String msg){System.out.println("消费者接收到topic.queue2的消息:【" + msg + "】");}
}


在这里插入图片描述



http://www.yayakq.cn/news/659889/

相关文章:

  • 天津网站制作策划什么推广方法最有效
  • 英文外贸发布网站沈阳响应式网站制作
  • 东莞免费网站建设网络营销wordpress登录没链接
  • 新乡市网站建设有哪些公司个人主页不会展示哪些内容
  • 网站建设问卷调查表互联网保险与传统保险的区别
  • 外汇网站怎么做优化食品网站制作
  • 做外贸哪个网站看外汇免费asp地方门户网站系统
  • 服装电子商务网站设计杭州市区网站制作单位
  • 响应式相册网站模板下载简易个人博客网站源码
  • 深圳公司网站设wordpress字体选择
  • wordpress评论主题宁波seo深度优化平台有哪些
  • 如何用微信建设网站卖东西青岛中嘉建设集团网站
  • 电子商务网站的数据库怎么做医疗网络营销外包
  • 建站必须要域名吗游戏登录器列表更新网站建设
  • 吴桥网站建设公司如何在个人网上建网站
  • 现代感网站黑客黑网站是做网站
  • 外贸seo网站大全网站域名背景
  • 辽宁建设集团招聘信息网站企业宣传网站源码
  • 网站的风格分析免费一级域名和空间
  • 有哪些网站可以找兼职做交互设计考研太难了
  • 手机怎么自己创造网站服务营销7p理论
  • html做的网站排版错误女性时尚网站模板
  • 建站行业是什么意思百度推广代运营
  • 宝安网站推广塑业东莞网站建设
  • 手机上能搭建网站吗找人做网站协议
  • 做qq空间动态皮肤网站天猫商城网站设计分析
  • 免费建站免费网站wordpress主题头条
  • 网站怎么查看访问量建设项目验收 网站
  • 烟台网站建设平台网站霸屏怎么做
  • 十大中文网站排名网站前后端全部做需要多少钱