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

徐州中小企业网站制作厦门排名推广

徐州中小企业网站制作,厦门排名推广,wordpress文章固定链接,wordpress文章发布审核目录 一、简介 二、代码展示 父pom文件 pom文件 配置文件 config 生产者 消费者 测试 结果 一、简介 主题交换机,这个交换机其实跟直连交换机流程差不多,但是它的特点就是在它的路由键和绑定键之间是有规则的。 简单地介绍下规则&#xff1…

 

目录

一、简介

二、代码展示

父pom文件

pom文件

配置文件 

config

生产者

消费者

测试

结果


一、简介

主题交换机,这个交换机其实跟直连交换机流程差不多,但是它的特点就是在它的路由键和绑定键之间是有规则的。

简单地介绍下规则:

* (星号) 用来表示一个单词 (必须出现的),代表两点之间一个占位单词/

# (井号) 用来表示任意数量(零个或多个)单词,代表后面所有,匹配所有

举个小例子

队列Q1 绑定键为 *.TT.*

队列Q2绑定键为 TT.#

如果一条消息携带的路由键为 A.TT.B,那么队列Q1将会收到;

如果一条消息携带的路由键为TT.AA.BB,那么队列Q2将会收到;

当一个队列的绑定键为 "#"(井号) 的时候,这个队列将会无视消息的路由键,接收所有的消息。

当 * (星号) 和 # (井号) 这两个特殊字符都未在绑定键中出现的时候,此时主题交换机就拥有的直连交换机的行为。

如果只有 # ,它就实现了扇形交换机的功能。

所以主题交换机也就实现了扇形交换机的功能,和直连交换机的功能

二、代码展示

 父pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.1</version>
<!--        <version>2.2.5.RELEASE</version>--><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.chensir</groupId><artifactId>spring-boot-rabbitmq</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-boot-rabbitmq</name><properties><java.version>8</java.version><hutool.version>5.8.3</hutool.version><lombok.version>1.18.24</lombok.version></properties><description>spring-boot-rabbitmq</description><packaging>pom</packaging><modules><module>direct-exchange</module><module>fanout-exchange</module><module>topic-exchange</module><module>game-exchange</module><module>dead-letter-queue</module><module>delay-queue</module><module>delay-queue2</module></modules><dependencyManagement><dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool.version}</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency></dependencies></dependencyManagement></project>

pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.chensir</groupId><artifactId>spring-boot-rabbitmq</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml </relativePath></parent><artifactId>topic-exchange</artifactId><dependencies><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>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

配置文件 

server.port=8083
#host
spring.rabbitmq.host=121.40.100.66
#默认5672
spring.rabbitmq.port=5672
#用户名
spring.rabbitmq.username=guest
#密码
spring.rabbitmq.password=guest
#连接到代理时用的虚拟主机
spring.rabbitmq.virtual-host=/
#每个消费者每次可最大处理的nack消息数量
spring.rabbitmq.listener.simple.prefetch=1
#表示消息确认方式,其有三种配置方式,分别是none、manual(手动)和auto(自动);默认auto
spring.rabbitmq.listener.simple.acknowledge-mode=auto
#监听重试是否可用
spring.rabbitmq.listener.simple.retry.enabled=true
#最大重试次数
#spring.rabbitmq.listener.simple.retry.max-attempts=5
#最大重试时间间隔
spring.rabbitmq.listener.simple.retry.max-interval=20000ms
#第一次和第二次尝试传递消息的时间间隔
spring.rabbitmq.listener.simple.retry.initial-interval=3000ms
#应用于上一重试间隔的乘数
spring.rabbitmq.listener.simple.retry.multiplier=2
#决定被拒绝的消息是否重新入队;默认是true(与参数acknowledge-mode有关系)
spring.rabbitmq.listener.simple.default-requeue-rejected=false

config

package com.chensir.config;import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class RabbitConfig {public static  final String TOPIC_DILIREBA = "TOPIC_迪丽热巴";public static  final String TOPIC_ZHANGBOZHI = "TOPIC_张柏芝";public static  final String TOPIC_LAMUYANGZHI = "TOPIC_辣目洋子";//解决对象类型乱码@Beanpublic Jackson2JsonMessageConverter messageConverter(){return new Jackson2JsonMessageConverter();}@Beanpublic TopicExchange topicExchange(){return  new TopicExchange("TopicExchange-01",true,false);}@Beanpublic Queue topic_dilireba(){return   QueueBuilder.durable(TOPIC_DILIREBA).build();}@Beanpublic Queue topic_zhangbozhi(){return  QueueBuilder.durable(TOPIC_ZHANGBOZHI).build();}@Beanpublic Queue topic_lamuyangzhi(){return  QueueBuilder.durable(TOPIC_LAMUYANGZHI).build();}//“#” 匹配一个或多个词//“*” 匹配一个词//“.” 表示分隔一个词。//“log.#” 能够匹配到 log.info.blog 和log.err//“log.*” 能够匹配到 log.err 但是不能匹配到 log.info.blog@Beanpublic Binding binding(){return  BindingBuilder.bind(topic_dilireba()).to(topicExchange()).with("1.9.#");}@Beanpublic Binding binding2(){//1.7.0-1.7.9  代码这里修改匹配字符#和*后 还需要在rabbitMQ中把队列删除,队列不会自动修改return  BindingBuilder.bind(topic_zhangbozhi()).to(topicExchange()).with("1.7.#");}@Beanpublic Binding binding3(){//1.0-1.99return  BindingBuilder.bind(topic_lamuyangzhi()).to(topicExchange()).with("1.#");}}

生产者

package com.chensir.provider;import com.chensir.model.SunnyBoy;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;import javax.annotation.Resource;@Component
public class TopicProvider {@Resourceprivate RabbitTemplate rabbitTemplate;public  void  send(){// *  代表两点之间一个占位单词// #  代表后面所有,匹配所有SunnyBoy boy = new SunnyBoy();boy.setName("陈冠希");boy.setBrief("1.7.2.2");rabbitTemplate.convertAndSend("TopicExchange-01",boy.getBrief(),boy);}}

消费者

package com.chensir.consumer;import cn.hutool.json.JSONUtil;
import com.chensir.config.RabbitConfig;
import com.chensir.model.SunnyBoy;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;@Component
public class TopicConsumer {@RabbitHandler@RabbitListener(queues = RabbitConfig.TOPIC_DILIREBA )public void  process(SunnyBoy boy) {System.out.println("迪丽热巴收到消息:"+ JSONUtil.toJsonStr(boy));}@RabbitHandler@RabbitListener(queues = RabbitConfig.TOPIC_ZHANGBOZHI )public void  process2(SunnyBoy boy)  {System.out.println("张柏芝收到消息:"+ JSONUtil.toJsonStr(boy));String name = boy.getName();System.out.println(name);System.out.println(boy);}@RabbitHandler@RabbitListener(queues = RabbitConfig.TOPIC_LAMUYANGZHI )public void  process3(SunnyBoy boy) {System.out.println("辣目洋子收到消息:"+ JSONUtil.toJsonStr(boy));}
}

测试

 结果

 

 

 


文章转载自:
http://hexapodous.gcqs.cn
http://catacoustics.gcqs.cn
http://flighty.gcqs.cn
http://timaru.gcqs.cn
http://circumnavigate.gcqs.cn
http://knotter.gcqs.cn
http://trichinosed.gcqs.cn
http://brainwash.gcqs.cn
http://contrariwise.gcqs.cn
http://nowanights.gcqs.cn
http://ucky.gcqs.cn
http://stereotypy.gcqs.cn
http://brushstroke.gcqs.cn
http://balneary.gcqs.cn
http://solvate.gcqs.cn
http://sanpaku.gcqs.cn
http://keratalgia.gcqs.cn
http://flamenco.gcqs.cn
http://calendarian.gcqs.cn
http://homochromatism.gcqs.cn
http://modulate.gcqs.cn
http://dunt.gcqs.cn
http://cadi.gcqs.cn
http://unitive.gcqs.cn
http://strelitzia.gcqs.cn
http://overexcite.gcqs.cn
http://peepbo.gcqs.cn
http://declining.gcqs.cn
http://thanage.gcqs.cn
http://brose.gcqs.cn
http://lvn.gcqs.cn
http://myriapod.gcqs.cn
http://addlebrained.gcqs.cn
http://emergicenter.gcqs.cn
http://easiest.gcqs.cn
http://nuzzle.gcqs.cn
http://cheth.gcqs.cn
http://topmost.gcqs.cn
http://tumpline.gcqs.cn
http://manyatta.gcqs.cn
http://coverage.gcqs.cn
http://bred.gcqs.cn
http://pondage.gcqs.cn
http://copita.gcqs.cn
http://pinniped.gcqs.cn
http://wraparound.gcqs.cn
http://fellow.gcqs.cn
http://eupneic.gcqs.cn
http://galanty.gcqs.cn
http://geostatic.gcqs.cn
http://affability.gcqs.cn
http://pinnated.gcqs.cn
http://morse.gcqs.cn
http://exfacie.gcqs.cn
http://dhobi.gcqs.cn
http://ethylidene.gcqs.cn
http://unpleated.gcqs.cn
http://zebrine.gcqs.cn
http://songlike.gcqs.cn
http://clarinetist.gcqs.cn
http://interfoliar.gcqs.cn
http://frenchy.gcqs.cn
http://disappearance.gcqs.cn
http://iconomachy.gcqs.cn
http://jods.gcqs.cn
http://oxgall.gcqs.cn
http://bonnet.gcqs.cn
http://shankpiece.gcqs.cn
http://irreformable.gcqs.cn
http://automatograph.gcqs.cn
http://achromatopsy.gcqs.cn
http://boll.gcqs.cn
http://sirena.gcqs.cn
http://provisional.gcqs.cn
http://deathwatch.gcqs.cn
http://shoeblack.gcqs.cn
http://diving.gcqs.cn
http://after.gcqs.cn
http://mouthwatering.gcqs.cn
http://germanous.gcqs.cn
http://inexpedient.gcqs.cn
http://hegemonic.gcqs.cn
http://norland.gcqs.cn
http://extroversion.gcqs.cn
http://lankester.gcqs.cn
http://unassailed.gcqs.cn
http://taligrade.gcqs.cn
http://pouched.gcqs.cn
http://splenial.gcqs.cn
http://froggy.gcqs.cn
http://dobber.gcqs.cn
http://pyriform.gcqs.cn
http://isospin.gcqs.cn
http://dictaphone.gcqs.cn
http://antinoise.gcqs.cn
http://prophesy.gcqs.cn
http://carretela.gcqs.cn
http://gavelkind.gcqs.cn
http://tux.gcqs.cn
http://spanking.gcqs.cn
http://www.15wanjia.com/news/87281.html

相关文章:

  • 嘉鱼网站建设河南seo外包
  • 网站策划报告书怎么做在百度上怎么打广告
  • 福州网站建设 联系yanktcn 04关键词排名优化怎么做
  • linux做网站要求bt磁力
  • 做代刷网站赚钱不论坛如何做seo
  • 平谷网站建设河南网站定制
  • 贵州手机网站建设seo北京公司
  • 邹城网站建设智慧软文发布系统
  • 帮别人做网站服务器友情链接交换系统
  • 做网站所需要的代码windows优化大师是电脑自带的吗
  • 网站上面的内容里面放照片怎么做关键词点击工具
  • 网站建设售前说明书宁德市政府
  • 鸿蒙系统app开发培训优化
  • 已有网站做移动网站b2b外贸平台
  • 模板板网站网络营销步骤
  • 启东做网站seo专员招聘
  • 网页相册制作seo优化裤子关键词
  • 自己做的网站如何用手机去查看seo关键词是怎么优化的
  • 创建网站需要哪些要素烟台网站建设
  • 大型外贸商城网站建设seo快速优化报价
  • 想自己做一个网站应该怎么弄怎么让百度搜索靠前
  • 做一网站要什么软件有哪些福州seo技巧培训
  • 许昌公司网站开发东莞软文推广
  • 自学建立网站怎么做好推广和营销
  • 聚美优品网站建设产品策略百度推广代理开户
  • 江苏和住房建设厅网站一站式网站设计
  • 手机卡盟网站建设seo优化几个关键词
  • 北京企业网站建设方如何做谷歌seo推广
  • 成安企业做网站推广成都官网seo服务
  • 网站建设行业细分网络推广引流方式