您现在的位置是:热点 >>正文
自研 Pulsar Starter:Winfun-Pulsar-Spring-Boot-Starter
热点6281人已围观
简介...
里程碑 版本 功能点 作者 完成 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=winulfun 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 private&nsabsp;PulsarTemplate pulsarTemplate; @Autowired private PulsarProperties pulsarProperties; /*** * 往指定topic发送消息 * @author winfun * @param topic topic r * @param msg msg * @return {@link String } **/ @GetMapping("/{topic}/{msg}") public String send(@PathVariable("topic") String topic,@PathVariable("msg") String msg) throws ExStception { this.pulsarTemplate.createBuilder().persistent(Boolean.TRUE) .tenant(this.pulsarProperties.getTenant()) .namespace(this.pulsarPropearrties.getNamespace()) .topic(topic) .send(msg); return "success"; } } 3.4、消费消息 /** * @authoter: winfun * @date: 2021/8/20 8:13 下午 **/ @Slf4j @PulsarListener(topics = {"test-topic2"}, threadPool = @ThreadPool( &nbsr:p; coreThreads = 2, maxCWioreThreads = 3, threadPoolName = "test-thread-pool")) public class ConsumerListener extends BaseMessageListener&nnfbsp;{ /** * 消费消息 * @param consumer 消费者 * @param msg 消息 */ @Override protected void doReceived(Consumer consumer, Meunssage msg) { log.info("成功消费消息:{}",msg.getValue()); try { consumer.acknowledge(msg); } catch (PulsarClientException e) &-P#123; e.printStackTrace(); } } /*** * 是否开启异步消费 * @return {@link Boolean } **/&nulbsp; @Override public Boolean enableAsync() { return Boolean.TRUE; } } 四、源码
源码就不放在这里分析了,大家可到Github上看看,如果有什么代码上面的建议或意见,欢迎大家提MR。
Tags:
相关文章
云安全日报211210:Apache Log4j2发现远程代码执行漏洞,需要尽快升级
热点Apache Log4j2是一款非常优秀的Java日志框架,它在各大交易所、钱包、DeFi项目中广泛使用。12月9日,Apache官方发布了紧急安全更新,修复了Apache Log4j2中发现的远程代...
【热点】
阅读更多云计算开发:Python3-title()方法详解
热点描述 Python title() 方法返回"标题化"的字符串,就是说所有单词的首个字母转化为大写,其余字母均为小写(见 istitle())。 语法 以下是 title() 方法语法: str.ti...
【热点】
阅读更多亚马逊正在进一步蚕食传统媒体的市场份额
热点来源:智通财经网 智通财经App获悉,亚马逊的Prime TV和亚马逊旗下的property Twitch获得了NFL的旧金山49人队与亚利桑那红雀队比赛的独家转播权。 一场比赛的独家转播并不一定意味...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.polliwogs.com/search/谷歌快排系统官网【tg:seogoogle987】,NiN
- https://www.remit.co.jp/zh/?s=谷歌快排系统官网【tg:seogoogle987】,tw4
- https://www.kores.com/?s=谷歌快排系统官网【tg:seogoogle987】,nd0
- https://www.varian.com/en-au/search?cat=113&search=谷歌快排系统官网【tg:seogoogle987】,rhP
- https://dict.naver.com/dict.search?dicQuery&query=谷歌快排系统官网【tg:seogoogle987】EC1
- https://www.abbreviations.com/谷歌快排系统官网【tg:seogoogle987】nyu
- https://www.qidulp.com/search?query=谷歌快排系统官网【tg:seogoogle987】,Fy8
- https://www.le-trend.com/en/search/=谷歌快排系统官网【tg:seogoogle987】,1a2
- https://www.remit.co.jp/vi/?s=谷歌快排系统官网【tg:seogoogle987】3Lp
- https://www.rostaing.com/catalogsearch/result/?cat=22&q=谷歌快排系统官网【tg:seogoogle987】,ftS
- https://yokohama-oht.com/?action=CHECK&s=谷歌快排系统官网【tg:seogoogle987】,ReR
- https://www.teamlab.art/th/?submit=谷歌快排系统官网【tg:seogoogle987】,lgH
- https://www.searcychamber.com/list/search?AsfnA=DtkTQzs&q=谷歌快排系统官网【tg:seogoogle987】,NjX
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=谷歌快排系统官网【tg:seogoogle987】,lFH
- https://www.yidian51.com/taobao/谷歌快排系统官网【tg:seogoogle987】,d67
- https://www.remit.co.jp/pt/?action=CHECK&s=谷歌快排系统官网【tg:seogoogle987】,cQM
- https://www.metaltix.com/?view=tours&filter=search&q=谷歌快排系统官网【tg:seogoogle987】,BpZ
- https://www.whatsonstage.com/search?cat=64&term=谷歌快排系统官网【tg:seogoogle987】,g7E
- https://www.lezhin.com/ko/tags/谷歌快排系统官网【tg:seogoogle987】,Gg4
- https://www.vivaraise.fr/catalogsearch/result/?q=谷歌快排系统官网【tg:seogoogle987】,FAK
- https://www.lifesciencesweden.se/search?q=谷歌快排系统官网【tg:seogoogle987】,SCz
- https://www.seforall.org/search?keywords=谷歌快排系统官网【tg:seogoogle987】,RFn
- https://www.mesec.cz/vyhledavani/?qs=谷歌快排系统官网【tg:seogoogle987】,gIg
- https://www.lindseymedicalsupply.com/search/谷歌快排系统官网【tg:seogoogle987】,o4A
- https://www.remit.co.jp/vi/?s=谷歌快排系统官网【tg:seogoogle987】iG5
- https://www.abbreviations.com/谷歌快排系统官网【tg:seogoogle987】ype
- https://www.miamiopenmri.com/?action=CHECK&s=谷歌快排系统官网【tg:seogoogle987】,1cG
- https://www.kingston.gov.uk/site-search/results/?q=谷歌快排系统官网【tg:seogoogle987】,xwx
- https://www.schenckprocess.com/search?q=谷歌快排系统官网【tg:seogoogle987】,XZk
- https://www.stormberg.com/no/search?q=谷歌快排系统官网【tg:seogoogle987】,MGJ
- https://www.teamlab.art/fr/?submit=谷歌快排系统官网【tg:seogoogle987】,58x
- https://www.kissthekangaroo.com.au/index.php?route=product/search&tag=谷歌快排系统官网【tg:seogoogle987】,yMA
- https://www.shopping.com/search.html?keyword=谷歌快排系统官网【tg:seogoogle987】,dJe
- https://www.wilsonart.com/catalogsearch/result/?action=CHECK&q=谷歌快排系统官网【tg:seogoogle987】,95g
- https://www.impactpool.org/search/?type=79&q=谷歌快排系统官网【tg:seogoogle987】W8o
- https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=谷歌快排系统官网【tg:seogoogle987】,Ydc
- https://yscc1986.net/search/谷歌快排系统官网【tg:seogoogle987】RIl
- https://jihoon471.cafe24.com/product/search.html?banner_action=&keyword=谷歌快排系统官网【tg:seogoogle987】Lqi
- https://www.lyrics.com/lyrics/kkk3谷歌快排系统官网【tg:seogoogle987】,dvW
- https://www.sportbiketracktime.com/index.php?route=product/search&tag=谷歌快排系统官网【tg:seogoogle987】,rks
- https://wwwcp.umes.edu/search/谷歌快排系统官网【tg:seogoogle987】,XLB
- https://www.goodreads.com/quotes/tag/谷歌快排系统官网【tg:seogoogle987】PTu
- https://www.swanagerailway.co.uk/search?q=谷歌快排系统官网【tg:seogoogle987】,kEz
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌快排系统官网【tg:seogoogle987】,l9Y
- https://www.takachi-enclosure.com/search?eqYB=gnI31Ou&text=谷歌快排系统官网【tg:seogoogle987】,YtN
- https://www.wikiart.org/pt/Search/谷歌快排系统官网【tg:seogoogle987】,SG7
- https://www.temu.com/search_result.html?search_key=谷歌快排系统官网【tg:seogoogle987】jJ4
- https://www.msrenewal.com/search/谷歌快排系统官网【tg:seogoogle987】,rG7
- https://www.manga-news.com/index.php/recherche/?q=谷歌快排系统官网【tg:seogoogle987】,hfO
- https://www.ncetm.org.uk/search?action=CHECK&q=谷歌快排系统官网【tg:seogoogle987】,0kD