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

揭阳做网站哪个好seo软文推广

揭阳做网站哪个好,seo软文推广,网站后台权限设计,扬中网站推广服务一、前言 本篇主要是围绕着 Spring Boot 3.x 与 RabbitMQ 的动态配置集成,比如动态新增 RabbitMQ 交换机、队列等操作。二、默认RabbitMQ中的exchange、queue动态新增及监听 1、新增RabbitMQ配置 RabbitMQConfig.java import org.springframework.amqp.rabbit.a…

一、前言

本篇主要是围绕着 Spring Boot 3.x 与 RabbitMQ 的动态配置集成,比如动态新增 RabbitMQ 交换机、队列等操作。

二、默认RabbitMQ中的exchange、queue动态新增及监听

1、新增RabbitMQ配置

RabbitMQConfig.java
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** @className: RabbitConfig* @program: chain* @description: RabbitMQ 配置类* @author: kenny* @create: 2024-10-03 21:59* @version: 1.0.0*/
@Configuration
@EnableRabbit
public class RabbitMQConfig {/*** 创建 RabbitTemplate, 用于发送消息** @return RabbitTemplate*/@Beanpublic RabbitTemplate rabbitTemplate() {return new RabbitTemplate();}/*** 创建 RabbitAdmin, 用于创建 Exchange 和 Queue** @param rabbitTemplate RabbitTemplate* @return RabbitAdmin*/@Beanpublic RabbitAdmin rabbitAdmin(RabbitTemplate rabbitTemplate) {return new RabbitAdmin(rabbitTemplate);}
}

2、新增RabbitMQ动态操作组件

RabbitDynamicConfigService.java
RabbitDynamicConfigService.java 中包含了不同类型Exchange的创建、删除,Queue的创建和删除、绑定Exchange
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.Map;/*** @className: RabbitDynamicConfigService* @program: chain* @description: 动态创建队列和交换机* @author: kenny* @create: 2024-10-03 23:49* @version: 1.0.0*/
@Slf4j
@Service
public class RabbitDynamicConfigService {/*** 为了解决循环依赖问题*/private final RabbitAdmin rabbitAdmin;private final RabbitListenerService rabbitListenerService;@Autowiredpublic RabbitDynamicConfigService(RabbitAdmin rabbitAdmin,RabbitListenerService rabbitListenerService) {this.rabbitAdmin = rabbitAdmin;this.rabbitListenerService = rabbitListenerService;}/*** 动态创建队列,并持久化** @param queueName 队列名称*/public void createQueue(String queueName) {// 队列持久化Queue queue = new Queue(queueName, true);// 创建队列rabbitAdmin.declareQueue(queue);System.out.println("队列创建成功: " + queueName);}/*** 动态创建队列,并持久化** @param queueName 队列名称*/public void createQueue(String queueName, Boolean isListener) {// 队列持久化Queue queue = new Queue(queueName, true);// 创建队列rabbitAdmin.declareQueue(queue);System.out.println("队列创建成功: " + queueName);if (!isListener) {return;}rabbitListenerService.createListener(queueName);}/*** 动态创建交换机,并持久化** @param exchangeName 交换机名称*/public void createExchange(String exchangeName) {// 交换机持久化DirectExchange exchange = new DirectExchange(exchangeName, true, false);rabbitAdmin.declareExchange(exchange);log.info("交换机创建成功: {}", exchangeName);}// 动态创建 Fanout 交换机public void createDirectExchange(String exchangeName) {DirectExchange fanoutExchange = new DirectExchange(exchangeName, true, false); // 持久化rabbitAdmin.declareExchange(fanoutExchange);log.info("Direct 交换机创建成功: {}", exchangeName);}// 动态创建 Fanout 交换机public void createFanoutExchange(String exchangeName) {FanoutExchange fanoutExchange = new FanoutExchange(exchangeName, true, false); // 持久化rabbitAdmin.declareExchange(fanoutExchange);log.info("Fanout 交换机创建成功: {}", exchangeName);}// 动态创建 Topic 交换机public void createTopicExchange(String exchangeName) {TopicExchange topicExchange = new TopicExchange(exchangeName, true, false); // 持久化rabbitAdmin.declareExchange(topicExchange);log.info("Topic 交换机创建成功: {}", exchangeName);}// 动态创建 Headers 交换机public void createHeadersExchange(String exchangeName) {HeadersExchange headersExchange = new HeadersExchange(exchangeName, true, false); // 持久化rabbitAdmin.declareExchange(headersExchange);log.info("Headers 交换机创建成功: {}", exchangeName);}/*** 动态绑定队列到交换机,并指定路由键** @param queueName    队列名称* @param exchangeName 交换机名称* @param routingKey   路由键*/public void bindQueueToExchange(String queueName, String exchangeName, String routingKey) {Queue queue = new Queue(queueName);DirectExchange exchange = new DirectExchange(exchangeName);Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey);rabbitAdmin.declareBinding(binding);log.info("绑定创建成功: {}", queueName + " -> {}", exchangeName + " 使用路由键: {}", routingKey);}/*** 动态绑定队列到交换机,并指定路由键** @param queueName    队列名称* @param exchangeName 交换机名称* @param routingKey   路由键*/public void moreExchangeTypeBindQueueToExchange(String queueName, String exchangeType, String exchangeName, String routingKey, Map<String, Object> headers) {switch (exchangeType) {case "fanout" -> bindQueueToExchange(queueName, exchangeName, routingKey);case "direct" -> bindQueueToDirectExchange(queueName, exchangeName, routingKey);case "topic" -> bindQueueToTopicExchange(queueName, exchangeName, routingKey);case "headers" -> bindQueueToHeadersExchange(queueName, exchangeName, headers);default -> throw new IllegalArgumentException("不支持的交换机类型: " + exchangeType);}}/*** 动态绑定队列到交换机,并指定路由键(exchange: direct)** @param queueName    队列名称* @param exchangeName 交换机名称*/public void bindQueueToFanoutExchange(String queueName, String exchangeName) {Queue queue = new Queue(queueName);FanoutExchange exchange = new FanoutExchange(exchangeName);Binding binding = BindingBuilder.bind(queue).to(exchange);rabbitAdmin.declareBinding(binding);log.info("绑定创建成功: {}", queueName + " -> {}", exchangeName);}/*** 动态绑定队列到交换机,并指定路由键(exchange: direct)** @param queueName    队列名称* @param exchangeName 交换机名称* @param routingKey   路由键*/public void bindQueueToDirectExchange(String queueName, String exchangeName, String routingKey) {Queue queue = new Queue(queueName);DirectExchange exchange = new DirectExchange(exchangeName);Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey);rabbitAdmin.declareBinding(binding);log.info("绑定创建成功: {}", queueName + " -> {}", exchangeName + " 使用路由键: {}", routingKey);}/*** 动态绑定队列到交换机,并指定路由键(exchange: topic)** @param queueName    队列名称* @param exchangeName 交换机名称* @param routingKey   路由键*/public void bindQueueToTopicExchange(String queueName, String exchangeName, String routingKey) {Queue queue = new Queue(queueName);TopicExchange exchange = new TopicExchange(exchangeName);Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey);rabbitAdmin.declareBinding(binding);log.info("绑定创建成功: {}", queueName + " -> {}", exchangeName + " 使用路由键: {}", routingKey);}/*** 动态绑定队列到交换机,并指定路由键(exchange: headers)** @param queueName    队列名称* @param exchangeName 交换机名称* @param headers      路由键*/public void bindQueueToHeadersExchange(String queueName, String exchangeName, Map<String, Object> headers) {Queue queue = new Queue(queueName);HeadersExchange exchange = new HeadersExchange(exchangeName);Binding binding = BindingBuilder.bind(queue).to(exchange).whereAll(headers).match();rabbitAdmin.declareBinding(binding);log.info("队列 {}", queueName + " 已绑定到 Headers 交换机 {}", exchangeName + ",使用头部匹配规则: {}", headers);}/*** 动态删除队列** @param queueName 队列名称*/public void deleteQueue(String queueName) {rabbitAdmin.deleteQueue(queueName);log.info("队列删除成功: {}", queueName);}/*** 动态删除交换机** @param exchangeName 交换机名称*/public void deleteExchange(String exchangeName) {rabbitAdmin.deleteExchange(exchangeName);log.info("交换机删除成功: {}", exchangeName);}
}

3、RabbitMQ中队列的动态监听

RabbitListenerService.java
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** @className: RabbitListenerService* @program: chain* @description: RabbitMQ监听器Service组件* @author: kenny* @create: 2024-10-04 01:40* @version: 1.0.0*/
@Slf4j
@Service
public class RabbitListenerService {// 为了解决循环依赖问题private final SimpleRabbitListenerContainerFactory listenerContainerFactory;private final ConnectionFactory connectionFactory;@Autowiredpublic RabbitListenerService(SimpleRabbitListenerContainerFactory listenerContainerFactory,ConnectionFactory connectionFactory) {this.listenerContainerFactory = listenerContainerFactory;this.connectionFactory = connectionFactory;}/*** 创建监听器容器并启动监听** @param queueName 队列名称*/public void createListener(String queueName) {// 创建并启动监听器容器SimpleMessageListenerContainer container = listenerContainerFactory.createListenerContainer();container.setConnectionFactory(connectionFactory);container.setQueueNames(queueName);// 监听逻辑处理container.setMessageListener(new MessageListenerAdapter(new Object() {public void handleMessage(String message) {System.out.println("收到来自RabbitMQ中队列:" + queueName + " 队列的消息:" + message);}}));// 启动监听器容器container.start();System.out.println("RabbitMQ队列监听器已启动:" + queueName);}
}

4、RabbitMQ中的Exchange、Queue动态操作接口

RabbitDynamicChannelController.java
import com.chain.air.rpp.exchange.rabbit.RabbitDynamicConfigService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;/*** @className: RabbitDynamicController* @program: chain* @description: RabbitMQ 动态创建队列、交换机,绑定等操作* @author: kenny* @create: 2024-10-04 00:22* @version: 1.0.0*/
@RestController
@RequestMapping("/rabbit/dynamic/channel")
public class RabbitDynamicChannelController {/*** 动态创建队列和交换机*/@Resourceprivate RabbitDynamicConfigService rabbitDynamicConfigService;/*** 动态创建队列** @param queueName 队列名称* @return 处理结果*/@GetMapping("/createQueue")public String createQueue(@RequestParam("queueName") String queueName) {rabbitDynamicConfigService.createQueue(queueName);return "队列已创建: " + queueName;}/*** 动态创建交换机** @param exchangeName 交换机名称* @return 处理结果*/@GetMapping("/createExchange")public String createExchange(@RequestParam("exchangeName") String exchangeName) {rabbitDynamicConfigService.createExchange(exchangeName);return "交换机已创建: " + exchangeName;}/*** 动态绑定队列和交换机** @param queueName    队列名称* @param exchangeName 交换机名称* @param routingKey   路由键* @return 处理结果*/@GetMapping("/bindQueue")public String bindQueueToExchange(@RequestParam("queueName") String queueName,@RequestParam("exchangeName") String exchangeName,@RequestParam("routingKey") String routingKey) {rabbitDynamicConfigService.bindQueueToExchange(queueName, exchangeName, routingKey);return "队列和交换机已绑定: " + queueName + " -> " + exchangeName;}/*** 动态删除队列** @param queueName 队列名称* @return 处理结果*/@GetMapping("/deleteQueue")public String deleteQueue(@RequestParam("queueName") String queueName) {rabbitDynamicConfigService.deleteQueue(queueName);return "队列已删除: " + queueName;}/*** 动态删除交换机** @param exchangeName 交换机名称* @return 处理结果*/@GetMapping("/deleteExchange")public String deleteExchange(@RequestParam("exchangeName") String exchangeName) {rabbitDynamicConfigService.deleteExchange(exchangeName);return "交换机已删除: " + exchangeName;}// 创建并绑定 Fanout 交换机@GetMapping("/createDirectExchange")public String createDirectExchange(@RequestParam String exchangeName, @RequestParam String queueName, @RequestParam String routingKey) {rabbitDynamicConfigService.createDirectExchange(exchangeName);rabbitDynamicConfigService.bindQueueToDirectExchange(queueName, exchangeName, routingKey);return "Fanout Exchange and Queue Binding created: " + exchangeName + " -> " + queueName + " with routing key: " + routingKey;}// 创建并绑定 Fanout 交换机@GetMapping("/createFanoutExchange")public String createFanoutExchange(@RequestParam String exchangeName, @RequestParam String queueName) {rabbitDynamicConfigService.createFanoutExchange(exchangeName);rabbitDynamicConfigService.bindQueueToFanoutExchange(queueName, exchangeName);return "Fanout Exchange and Queue Binding created: " + exchangeName + " -> " + queueName;}// 创建并绑定 Topic 交换机@GetMapping("/createTopicExchange")public String createTopicExchange(@RequestParam String exchangeName, @RequestParam String queueName, @RequestParam String routingKey) {rabbitDynamicConfigService.createTopicExchange(exchangeName);rabbitDynamicConfigService.bindQueueToTopicExchange(queueName, exchangeName, routingKey);return "Topic Exchange and Queue Binding created: " + exchangeName + " -> " + queueName + " with routing key: " + routingKey;}// 创建并绑定 Headers 交换机@GetMapping("/createHeadersExchange")public String createHeadersExchange(@RequestParam String exchangeName, @RequestParam String queueName, @RequestParam Map<String, String> headersMap) {Map<String, Object> headers = new HashMap<>(headersMap);rabbitDynamicConfigService.createHeadersExchange(exchangeName);rabbitDynamicConfigService.bindQueueToHeadersExchange(queueName, exchangeName, headers);return "Headers Exchange and Queue Binding created: " + exchangeName + " -> " + queueName + " with headers: " + headers;}
}

5、RabbitMQ中的Queue消息监听动态操作接口

RabbitChannelListenerController.java
import com.chain.air.rpp.exchange.rabbit.RabbitDynamicConfigService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;/*** @className: RabbitListenerController* @program: chain* @description: RabbitMQ 监听器 Controller 组件* @author: kenny* @create: 2024-10-04 01:30* @version: 1.0.0*/
@RestController
@RequestMapping("/rabbit/channel/listener")
public class RabbitChannelListenerController {@Resourceprivate RabbitDynamicConfigService rabbitDynamicConfigService;/*** 创建监听器,监听指定队列** @param queueName 队列名称* @return 处理结果*/@GetMapping("/queue")public String listenQueue(@RequestParam("queueName") String queueName) {rabbitDynamicConfigService.createQueue(queueName, true);return "开始监听队列:" + queueName;}
}

三、动态exchange、queue的测试

1、测试Exchange、Queue的动态创建和删除

2、测试Exchange和Queue的动态绑定

3、发送、接收消息测试动态创建Exchange、Queue

4、测试Queue的动态监听接口

下一篇:7、Spring Boot 3.x集成RabbitMQ动态实例等操作


文章转载自:
http://dinncoornamentalist.zfyr.cn
http://dinncocritical.zfyr.cn
http://dinncomisconduct.zfyr.cn
http://dinncodisgusting.zfyr.cn
http://dinncoquale.zfyr.cn
http://dinncomicrocephaly.zfyr.cn
http://dinncopinchcock.zfyr.cn
http://dinncoalabastrine.zfyr.cn
http://dinncosuperimpregnation.zfyr.cn
http://dinncosaltwater.zfyr.cn
http://dinncoturcophobe.zfyr.cn
http://dinncowhose.zfyr.cn
http://dinncoinositol.zfyr.cn
http://dinncoatelic.zfyr.cn
http://dinncofoggage.zfyr.cn
http://dinncoexeat.zfyr.cn
http://dinncohoneyed.zfyr.cn
http://dinncoevening.zfyr.cn
http://dinncomarcelle.zfyr.cn
http://dinncocoital.zfyr.cn
http://dinncogruntle.zfyr.cn
http://dinncosubliminal.zfyr.cn
http://dinncoexodontist.zfyr.cn
http://dinncoligate.zfyr.cn
http://dinncoinhumane.zfyr.cn
http://dinncodiluvialist.zfyr.cn
http://dinncothermit.zfyr.cn
http://dinncolentamente.zfyr.cn
http://dinncopolyphage.zfyr.cn
http://dinncostockbreeding.zfyr.cn
http://dinncotelephonograph.zfyr.cn
http://dinncokilovar.zfyr.cn
http://dinncoambidexterity.zfyr.cn
http://dinncolumphead.zfyr.cn
http://dinncodotage.zfyr.cn
http://dinncooutweep.zfyr.cn
http://dinncoflowstone.zfyr.cn
http://dinncopsychopathology.zfyr.cn
http://dinncoslumlord.zfyr.cn
http://dinncospanning.zfyr.cn
http://dinncoklunk.zfyr.cn
http://dinncofremdness.zfyr.cn
http://dinncoquadraphony.zfyr.cn
http://dinncohock.zfyr.cn
http://dinncoassociate.zfyr.cn
http://dinncouniserial.zfyr.cn
http://dinncotourer.zfyr.cn
http://dinncogarnet.zfyr.cn
http://dinncofathomable.zfyr.cn
http://dinncoscrambler.zfyr.cn
http://dinncodrammock.zfyr.cn
http://dinncointervocalic.zfyr.cn
http://dinncowindfall.zfyr.cn
http://dinncoprepuberal.zfyr.cn
http://dinncoamerce.zfyr.cn
http://dinncocarposporangium.zfyr.cn
http://dinncodevilish.zfyr.cn
http://dinncobacklash.zfyr.cn
http://dinncobotanist.zfyr.cn
http://dinncoanthracosis.zfyr.cn
http://dinncostoniness.zfyr.cn
http://dinncoanticarious.zfyr.cn
http://dinncoinwardness.zfyr.cn
http://dinncocuracy.zfyr.cn
http://dinncocommentator.zfyr.cn
http://dinncosequestrable.zfyr.cn
http://dinncoguillemot.zfyr.cn
http://dinncohemiacetal.zfyr.cn
http://dinncotenderness.zfyr.cn
http://dinncoreside.zfyr.cn
http://dinncomyofibril.zfyr.cn
http://dinncopastorless.zfyr.cn
http://dinncoczarina.zfyr.cn
http://dinncodeoxidation.zfyr.cn
http://dinncomargrave.zfyr.cn
http://dinncosnood.zfyr.cn
http://dinncoarises.zfyr.cn
http://dinncocrystallize.zfyr.cn
http://dinncoginzo.zfyr.cn
http://dinnconasaiism.zfyr.cn
http://dinncotut.zfyr.cn
http://dinncocompensability.zfyr.cn
http://dinnconitrid.zfyr.cn
http://dinncocardiodynia.zfyr.cn
http://dinncoschistoid.zfyr.cn
http://dinncopernoctation.zfyr.cn
http://dinncoadrenal.zfyr.cn
http://dinncocockneyism.zfyr.cn
http://dinncocrested.zfyr.cn
http://dinncoprenomen.zfyr.cn
http://dinncounacquainted.zfyr.cn
http://dinncocontact.zfyr.cn
http://dinncoverona.zfyr.cn
http://dinncopiercing.zfyr.cn
http://dinncomonachal.zfyr.cn
http://dinncoputrescence.zfyr.cn
http://dinncopuristic.zfyr.cn
http://dinncophotoelectric.zfyr.cn
http://dinncotawse.zfyr.cn
http://dinncoaversion.zfyr.cn
http://www.dinnco.com/news/94033.html

相关文章:

  • 网站改版建议策划书济源新站seo关键词排名推广
  • 织梦软件网站模板下载地址长沙seo关键词排名优化
  • 众筹网站的分析与设计google play官网下载
  • wordpress加站点描述高端营销型网站
  • 广州海珠网站开发设计网站建设介绍ppt
  • 济南市公众号网站建设怎么接游戏推广的业务
  • 公司网站哪家做的好网站如何优化排名
  • 三级网站域名下载百度投诉电话人工客服24小时
  • 信阳做网站公司汉狮价格开发一个网站
  • 网站开发全流程软件开发公司有哪些
  • 网站怎么去维护百度指数购买
  • 泰安网站建设运营费用网络营销模式案例
  • 广州云脑网站建设软件推广怎么赚钱
  • 温州哪家做网站怎么引流客源最好的方法
  • 自己做网站卖二手车河北百度推广seo
  • 做网站app公司前景网页在线客服免费版
  • 网站直播用php怎么做的百度风云榜小说排行榜
  • 河北邯郸做网站企业网站建设的重要性
  • 什么网站好建设上海百度seo牛巨微
  • 怎么在DW网站站点下建立两张网页网上推广方式
  • 厦门装修公司排名前十口碑推荐最优化方法
  • 网站怎么做流程最新营销模式有哪些
  • php网页设计实例代码优化水平
  • 网站备案需要那些资料做市场推广应该掌握什么技巧
  • 注册公司上海南京广告宣传公司seo
  • 网站建设 牛商网技术提供品牌宣传
  • 平顶山做网站推广海外网站推广优化专员
  • qq群推广链接互联网广告优化
  • 企业网站功能怎么设计谷歌商店下载安装
  • 网站改版的意义搜索引擎优化的目的是