您现在的位置是:热点 >>正文
自研 Pulsar Starter:Winfun-Pulsar-Spring-Boot-Starter
热点9339457人已围观
简介...
里程碑 版本 功能点 作者 完成 1.0.0 支持PulsarTemplate发送消息&支持自定义注解实例化Consumer监听消息 howinfun 1.1.0 支持动态开启/关闭Consumer消费线程池、支持自定义配置Consuemr消费线程池参数 howinfun 1.2.0 支持Spring容器停止时,释放Pulsar所有相关资源 howinfun TODO 1.3.0 支持多Pulsar数据源 howinfun TODO
一、背景
Pulsar 作为新生代云原生消息队列,越来越受到开发者的热爱;而我们现在基本上的项目都是基于 SpringBoot 上开发的,但是我们可以发现,至今都没有比较大众和成熟的关于 Pulsar 的 Starter,所以我们需要自己整一个,从而避免常规使用 Pulsar API 时产生大量的重复代码。
二、设计思路
由于是第一版的设计,所以我们是从简单开始,不会一开始就设计得很复杂,尽量保留 P自研ulsar API 原生的功能。
2.1、PulsarClient
我们都知道,不管是 Producer 还是 Consumer,都是由 PulsarClient 创建的。
当然了,PulsarClient 可以根据业务需要自定义很多参数,但是第一版的设计只会支持比较常用的参数。
我们这个组件支持下面功能点:
支持 PulsarClient 参数配置外部化,参数可配置在 applicatin.properties 中。 支持 applicatin.properties 提供配置提示信息。 读取外部配置文件,根据参数实例化 PulsarClient,并注入到 IOC 容器中。 2.2、Producer
Producer是发送消息的组件。
这里我们提供一个模版类,可以根据需求创建对应的 Producer 实例。 支持将 TopicProducer 关系缓存起来,避免重复创建 Producer 实例。 支持同步/异步发送消息。 2.3、Consumer
Consumer是消费消息的组件。
这 P里我们提供一个抽象类,开发者只需要集成此实现类并实现 doReceive 方法即可,即消费消息的逻辑方法。 接着还提供一个自定义注解,自定义注解支持自定义 Consmuer 配置,例如Topic、Tenant、Namespace等。 实现类加入上述自定义注解后,组件将会自动识别并且生成对应的 Consumer 实例。 支持同步/线程池异步消费。 三、使用例子 3.1、引入依赖 io.github.howinfun winfun-pulsar-spring-boot-starter 1.1.0 3.2、加入配置 pulsar.service-url=pulsar://127.0.0.1:6650 pulsar.tenant=winfulun pulsar.namespace=study pulsar.operation-timeout=30 pulsar.io-threads=10 pulsar.listener-threads=10 3.3、发送消息 /** * 发送消息 * @author: winfun **/ @RestController @RequestMapping("msg") public class MessageController { @Autowired privatesa PulsarTemplate pulsarTemplate; @Autowired private PulsarProperties pulsarProperties; /*** * 往指定topic发送消息 * @author winfun * @param topic topic &nr bsp; * @param msg msg * @return {@link String } **/ @GetMapping("/{topic}/{msg}") public String send(@PathVariable("topic") String topic,@PathVariable("msg") String msg) throwsSt Exception { this.pulsarTemplate.createBuilder().persistent(Boolean.TRUE) .tenant(this.pulsarProperties.getTenant()) .namespace(this.pularsarProperties.getNamespace()) .topic(topic) .send(msg); return "success"; } } 3.4、消费消息 /** * @autethor: winfun * @date: 2021/8/20 8:13 下午 **/ @Slf4j @PulsarListener(topics = {"test-topic2"}, threadPool = @ThreadPool( &r:nbsp; coreThreads = 2, &nbsWip;maxCoreThreads = 3, threadPoolName = "test-thread-pool")) public class ConsumerListener extends BaseMessageListenfner { /** * 消费消息 * @param consumer 消费者 * @param msg 消息 */ @Override protected void doReceived(Consumer consumer,&nunbsp;Message msg) { log.info("成功消费消息:{}",msg.getValue()); try { consumer.acknowledge(msg); } catch (PulsarClientException e) -P{ e.printStackTrace(); } } /*** * 是否开启异步消费 * @return {@link Boolean } **/ul @Override public Boolean enableAsync() { return Boolean.TRUE; } } 四、源码
源码就不放在这里分析了,大家可到Github上看看,如果有什么代码上面的建议或意见,欢迎大家提MR。
Tags:
相关文章
标签: 马云 陈伟 阿里巴巴 太极禅院
热点云梦级1月14日云梦级消息,据电商大V倪叔透露,马云前助理,阿里太极禅院创始人陈伟去世,在其告别会上有马云夫妇送的花圈。 倪叔表示,他与陈伟在马云墨宝拍卖会上相识,二人曾在太极禅院有一段非常美好的回忆...
【热点】
阅读更多标签: Gemini 3 Google 深度思考模式 Antigravity
热点云梦级11月19日云梦级消息,今天,谷歌正式发布 Gemini 3。它不仅是全球领先的多模态理解模型,更是谷歌迄今为止最强大的智能体(Agentic)和氛围编程(Vibe Coding)模型,能够提供...
【热点】
阅读更多DeepSeek爆红全球:量化对冲基金孵化的技术黑马如何撼动美国AI霸权
热点一家来自中国的AI实验室DeepSeek本周突然闯入全球视野,其聊天机器人应用登顶苹果App Store和Google Play下载榜首。这家公司采用计算高效技术训练的AI模型,引发华尔街分析师和科技...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.smics.com/tc/site/search?token=谷歌快排操作流程【tg:seogoogle987】,dPL
- https://www.resilienz-akademie.com/?cat=71&s=谷歌快排操作流程【tg:seogoogle987】,sgx
- https://www.teamlab.art/th/?submit=谷歌快排操作流程【tg:seogoogle987】,qAa
- https://www.parl.ca/legisinfo/fr/projets-de-loi?parlsession=all&view=list&keywords=谷歌快排操作流程【tg:seogoogle987】,vqP
- https://www.londontheatredirect.com/search/谷歌快排操作流程【tg:seogoogle987】,iW9
- https://www.safetv.go.kr/base/search/view?searchWord=谷歌快排操作流程【tg:seogoogle987】jnn
- https://www.ussalabama.com/?action=CHECK&s=谷歌快排操作流程【tg:seogoogle987】,zew
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=谷歌快排操作流程【tg:seogoogle987】TfG
- https://www.otakuninjahero.com/en/search/谷歌快排操作流程【tg:seogoogle987】,Kqq
- https://www.pearson.com/en-us/search.html?aq=谷歌快排操作流程【tg:seogoogle987】,gPi
- https://www.sic-info.org/?s=谷歌快排操作流程【tg:seogoogle987】,Yeq
- https://www.miamiopenmri.com/?action=CHECK&s=谷歌快排操作流程【tg:seogoogle987】,unt
- https://www.tumblr.com/tagged/谷歌快排操作流程【tg:seogoogle987】,5jh
- https://www.posten-portal.de/search?query=谷歌快排操作流程【tg:seogoogle987】,rkI
- https://www.kelsa.co.uk/catalogsearch/result/index/?T=1686132119291&q=谷歌快排操作流程【tg:seogoogle987】,W2p
- https://www.wilsonart.com/catalogsearch/result/?action=CHECK&q=谷歌快排操作流程【tg:seogoogle987】,XRz
- https://www.msrenewal.com/search/谷歌快排操作流程【tg:seogoogle987】,nZL
- https://www.maigoo.com/search/?block=&q=谷歌快排操作流程【tg:seogoogle987】,QKY
- https://www.pmindia.gov.in/en/?s=谷歌快排操作流程【tg:seogoogle987】,4hL
- https://www.vfw.org/search-results?q=谷歌快排操作流程【tg:seogoogle987】,Rbh
- https://www.teamlab.art/it/?submit=谷歌快排操作流程【tg:seogoogle987】,bNA
- https://www.oikos-tecnics.com/?s=谷歌快排操作流程【tg:seogoogle987】,DSc
- https://www.riohondo.edu/?action=QUERY&s=谷歌快排操作流程【tg:seogoogle987】,0Ry
- https://www.libros.unam.mx/catalogsearch/result/?cat=37&dir=asc&format=20&lit=20&manufacturer=3230&mode=list&order=year_edition&q=谷歌快排操作流程【tg:seogoogle987】,em4
- https://www.rookwinkel.nl/catalogsearch/result/index/?q=谷歌快排操作流程【tg:seogoogle987】,rne
- https://hsmoa.com/search?query=谷歌快排操作流程【tg:seogoogle987】TWM
- https://www.ucycle.com/search/=谷歌快排操作流程【tg:seogoogle987】,9BW
- https://www.vivaraise.fr/catalogsearch/result/?q=谷歌快排操作流程【tg:seogoogle987】,GsT
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=谷歌快排操作流程【tg:seogoogle987】evr
- https://www.sic-info.org/en/?s=谷歌快排操作流程【tg:seogoogle987】,tSV
- https://www.youm7.com/Home/Search?allwords=谷歌快排操作流程【tg:seogoogle987】,TWR
- https://www.safetv.go.kr/base/search/view?searchWord=谷歌快排操作流程【tg:seogoogle987】4uo
- https://xn--lgernevedlystskoven-lxb.dk/search/谷歌快排操作流程【tg:seogoogle987】,0ZW
- https://www.toy-people.com/?s=谷歌快排操作流程【tg:seogoogle987】,NU6
- https://www.wmfe.org/?s=谷歌快排操作流程【tg:seogoogle987】,Ary
- https://www.metaltix.com/?view=tours&filter=search&q=谷歌快排操作流程【tg:seogoogle987】,dUd
- https://www.silentiumpc.com/en/search/谷歌快排操作流程【tg:seogoogle987】,Sfj
- https://www.polar-tech.com/?action=QUERY&s=谷歌快排操作流程【tg:seogoogle987】,L5P
- https://www.thedp.com/page/search?q=谷歌快排操作流程【tg:seogoogle987】,tEv
- https://www.zutari.com/?s=谷歌快排操作流程【tg:seogoogle987】,mSZ
- https://www.sbaad.no/search/谷歌快排操作流程【tg:seogoogle987】,RT1
- https://www.quarterjacksurgery.co.uk/?AT=3rBy&s=谷歌快排操作流程【tg:seogoogle987】,WlF
- https://www.target.com/s?searchTerm=谷歌快排操作流程【tg:seogoogle987】,b7L
- https://www.wuv.edu/?s=谷歌快排操作流程【tg:seogoogle987】,r9s
- https://www.youtube.com/hashtag/谷歌快排操作流程【tg:seogoogle987】,QKC
- https://www.routesonline.com/search/?query=谷歌快排操作流程【tg:seogoogle987】,95S
- https://www.wellbees.com/index.php/catalogsearch/result/index/?q=谷歌快排操作流程【tg:seogoogle987】,tFP
- https://www.remit.co.jp/id/?s=谷歌快排操作流程【tg:seogoogle987】,uFa
- https://www.tmtpost.com/search?q=谷歌快排操作流程【tg:seogoogle987】,FH6
- https://wydden.com/?ID=r8w9WMSKWkOcmiaFWaUv0dzMdqZWfKtF&s=谷歌快排操作流程【tg:seogoogle987】,gq1