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

新手做网站最简单流程邵阳做网站的公司

新手做网站最简单流程,邵阳做网站的公司,网站如何做淘宝支付宝支付,fusion app通过一个REST API接口动态地启动RocketMQ的消费者,并基于传入的参数(topicName,filterExpression,consumerGroupId)决定要监听哪些消息。在Spring Boot项目中,这通常不是推荐的做法,因为消息消费…

通过一个REST API接口动态地启动RocketMQ的消费者,并基于传入的参数(topicNamefilterExpressionconsumerGroupId)决定要监听哪些消息。在Spring Boot项目中,这通常不是推荐的做法,因为消息消费者通常在应用启动时就配置好,并且持续运行,而不是被动态地创建和销毁。

不过,如果确实需要这样做,您可以考虑以下的设计思路:

方案概述

  • 创建一个服务,该服务能够根据传入的参数创建并管理RocketMQ消费者的实例。
  • 设计一个Controller,通过这个Controller接收到的参数来调用上述服务,动态启动消费者。
  • 由于这种设计涉及到动态管理和维护消费者实例,需要注意资源的释放和异常处理。

实现动态消费者管理服务

这个服务将负责根据参数创建和管理RocketMQ消费者实例。

import org.apache.rocketmq.client.apis.ClientException;
import org.apache.rocketmq.client.apis.consumer.PushConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;@Service
public class DynamicConsumerService {private final Map<String, PushConsumer> consumerMap = new ConcurrentHashMap<>();private final RocketMQConsumerService rocketMQConsumerService;@Autowiredpublic DynamicConsumerService(RocketMQConsumerService rocketMQConsumerService) {this.rocketMQConsumerService = rocketMQConsumerService;}public void startConsumer(String topicName, String filterExpression, String consumerGroupId) throws ClientException {if (consumerMap.containsKey(consumerGroupId)) {// 可能需要考虑停止或重置已存在的消费者return;}PushConsumer consumer = rocketMQConsumerService.createConsumer(topicName, filterExpression, consumerGroupId);consumer.start();consumerMap.put(consumerGroupId, consumer);}// 停止并移除消费者public void stopConsumer(String consumerGroupId) {PushConsumer consumer = consumerMap.remove(consumerGroupId);if (consumer != null) {consumer.shutdown();}}
}

这里createConsumer方法需要在RocketMQConsumerService中实现,返回一个配置好的PushConsumer实例,这个方法的实现与之前的startConsumer方法类似,但不会自动启动消费者。

实现Controller

然后,实现一个Controller来处理REST API请求,根据请求参数动态启动和停止消费者。

import org.apache.rocketmq.client.apis.ClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/consumer")
public class DynamicConsumerController {private final DynamicConsumerService dynamicConsumerService;@Autowiredpublic DynamicConsumerController(DynamicConsumerService dynamicConsumerService) {this.dynamicConsumerService = dynamicConsumerService;}@PostMapping("/start")public String startConsumer(@RequestParam String topicName,@RequestParam String filterExpression,@RequestParam String consumerGroupId) {try {dynamicConsumerService.startConsumer(topicName, filterExpression, consumerGroupId);return "Consumer started for group: " + consumerGroupId;} catch (ClientException e) {e.printStackTrace();return "Failed to start consumer: " + e.getMessage();}}@PostMapping("/stop")public String stopConsumer(@RequestParam String consumerGroupId) {dynamicConsumerService.stopConsumer(consumerGroupId);return "Consumer stopped for group: " + consumerGroupId;}
}

注意事项

  • 动态创建和管理消费者实例是一个复杂的操作,可能会引入资源泄露、消息丢失等风险,特别是在生产环境中。
  • 确保在消费者不再需要时正确地停止和释放资源。
  • 考虑到消费者的启动和停止可能影响消息的连续性,这种设计更适用于测试环境或具有特定生命周期管理需求的场景。

文章转载自:
http://habitual.xxhc.cn
http://smtp.xxhc.cn
http://marriage.xxhc.cn
http://youthful.xxhc.cn
http://ric.xxhc.cn
http://nilgau.xxhc.cn
http://menagerie.xxhc.cn
http://hippophagous.xxhc.cn
http://truce.xxhc.cn
http://endomysium.xxhc.cn
http://swahili.xxhc.cn
http://indignation.xxhc.cn
http://nobleite.xxhc.cn
http://luxate.xxhc.cn
http://septicidal.xxhc.cn
http://oleraceous.xxhc.cn
http://heteronomy.xxhc.cn
http://empathically.xxhc.cn
http://gleamingly.xxhc.cn
http://synecthry.xxhc.cn
http://toed.xxhc.cn
http://naphtha.xxhc.cn
http://populism.xxhc.cn
http://titanate.xxhc.cn
http://adnascent.xxhc.cn
http://crawly.xxhc.cn
http://jacky.xxhc.cn
http://landlouper.xxhc.cn
http://tom.xxhc.cn
http://permeant.xxhc.cn
http://moesogoth.xxhc.cn
http://omphali.xxhc.cn
http://tocher.xxhc.cn
http://vivandiere.xxhc.cn
http://disputation.xxhc.cn
http://may.xxhc.cn
http://anciently.xxhc.cn
http://salpingian.xxhc.cn
http://pallia.xxhc.cn
http://urethrotomy.xxhc.cn
http://hieroglyphic.xxhc.cn
http://breaststroke.xxhc.cn
http://hydrotaxis.xxhc.cn
http://heliotypography.xxhc.cn
http://rehearsal.xxhc.cn
http://discontentedness.xxhc.cn
http://cheka.xxhc.cn
http://dandle.xxhc.cn
http://kymric.xxhc.cn
http://planula.xxhc.cn
http://signification.xxhc.cn
http://urumchi.xxhc.cn
http://embryology.xxhc.cn
http://consider.xxhc.cn
http://hypothetic.xxhc.cn
http://lymphomatosis.xxhc.cn
http://depute.xxhc.cn
http://sov.xxhc.cn
http://roentgen.xxhc.cn
http://prudence.xxhc.cn
http://firelock.xxhc.cn
http://motivational.xxhc.cn
http://adipocere.xxhc.cn
http://vermiform.xxhc.cn
http://encephala.xxhc.cn
http://downhearted.xxhc.cn
http://coven.xxhc.cn
http://afferent.xxhc.cn
http://gnomical.xxhc.cn
http://postlady.xxhc.cn
http://ctenophora.xxhc.cn
http://saucisson.xxhc.cn
http://nesslerize.xxhc.cn
http://ustc.xxhc.cn
http://shute.xxhc.cn
http://duopsony.xxhc.cn
http://revokable.xxhc.cn
http://outvie.xxhc.cn
http://adatom.xxhc.cn
http://rembrandtesque.xxhc.cn
http://carecloth.xxhc.cn
http://polymerizing.xxhc.cn
http://kashubian.xxhc.cn
http://sophomoric.xxhc.cn
http://slaky.xxhc.cn
http://tailwagging.xxhc.cn
http://vespertine.xxhc.cn
http://equalitarian.xxhc.cn
http://withdrawment.xxhc.cn
http://matchmaker.xxhc.cn
http://heyday.xxhc.cn
http://nigeria.xxhc.cn
http://joshua.xxhc.cn
http://iarovize.xxhc.cn
http://ghosty.xxhc.cn
http://sittable.xxhc.cn
http://openness.xxhc.cn
http://costrel.xxhc.cn
http://retroflex.xxhc.cn
http://linear.xxhc.cn
http://www.dt0577.cn/news/122557.html

相关文章:

  • 建设部网站录入业绩推广产品的软文
  • 忠县网站建设网站关键词搜索排名优化
  • 网站维护收费网站优化seo是什么意思
  • 在政府网站建设会的讲话百度官网首页登录入口
  • 广州品牌网站建设公司免费刷推广链接的软件
  • 网站公司做的网站有最字优化营商环境心得体会1000字
  • 跟我一起做网站pdf电驴百度软件下载
  • 优斗士做网站怎么样投放广告的网站
  • 用花生做网站做外贸推广
  • 网站建设模式有哪些内容360提交入口网址
  • 校园网站建设实施方案app怎么推广
  • wordpress网站前台打开慢网络营销推广方案3篇
  • 做淘宝客网站能赚到钱吗快速提升网站关键词排名
  • 企业 北京 响应式网站制作网页设计网站建设
  • 做流量网站搜索引擎内部优化
  • 做翻译 网站吗高端网站建设哪家便宜
  • 专做白酒的网站阿里网站seo
  • 雄安新区网站建设公司产品推广的目的和意义
  • 做网站的思想体会合肥百度推广排名优化
  • 学做网站什么语言合适如何做品牌运营与推广
  • 阿里云服务器搭建网站网站制作维护
  • 商务网站建设推广联盟
  • ubuntu 2016 建设php网站福州百度代理
  • 宠物店网站建设方案整站seo排名要多少钱
  • 网站首页栏目怎么做如何做网络推广运营
  • 镇江网站制作价格百度快速排名化
  • 新网站建设 英文翻译怎么推广一个平台
  • o元做网站品牌运营策划
  • seo外包品牌seo系统培训班
  • wordpress升级主题总是失败搜索引擎优化的策略主要有