使用方式QMQ- https://github.com/quarcorp/qmqSprigBootStarterforQMQ- https://gitee.com/wjtree/qmq-sprig-boot-starter引入Mave依赖(已上传到中央仓库)<depedecy> <groupId>xi.wjtree.qmq</groupId> <artifactId>qmq-sprig-boot-starter</artifactId> <versio>1.0.0</versio></depedecy>添加SprigBoot配置(YML)sprig: applicatio: ame:qmq-demo qmq: #应用标识appcode,必填 app-code:qmq-demo #服务器地址metaserver,必填 meta-server:https://127.0.0.1:8080/meta/address #生产者配置,发送消息的线程池的设置,选填 producer: #发送线程数,默认3 sed-threads:3 #默认每次发送时最大批量大小,默认30 sed-batch:30 #如果消息发送失败,重试次数,默认10 sed-try-cout:10 #异步发送队列大小,默认10000 max-queue-size:10000 #使用QmqTemplate发送消息的默认主题,默认值default_subject template: default-subject:default_subject #消费者配置,消费消息的线程池的设置,选填 cosumer: #线程名称前缀,默认qmq-process thread-ame-prefix:qmq-process #线程池大小,默认2 core-pool-size:2 #最大线程池大小,默认2 max-pool-size:2 #线程池队列大小,默认1000 queue-capacity:1000 #消息主题和分组配置,选填 #使用QmqCosumer注解时,可使用SpEL表达式引入以下主题和分组 subject: sub1:sub1 sub2:sub2 sub3:sub3 #moresubject... group: group1:group1 group2:group2 group3:group3 #moregroup...loggig: level: #设置qmq-sprig-boot-starter的日志级别 xi.wjtree.qmq:traceserver: port:8989发送消息importorg.juit.Test;importorg.juit.ruer.RuWith;importorg.sprigframework.boot.test.cotext.SprigBootTest;importorg.sprigframework.test.cotext.juit4.SprigRuer;importquar.tc.qmq.Message;importquar.tc.qmq.MessageSedStateListeer;importxi.wjtree.qmq.QmqTemplate;importxi.wjtree.qmq.autocofigure.QmqProperties;importxi.wjtree.qmq.costat.QmqTimeUit;importxi.wjtree.qmq.iteral.QmqAlias;importxi.wjtree.qmq.iteral.QmqIgore;importjavax.aotatio.Resource;importjava.math.BigDecimal;importjava.text.ParseExceptio;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.cocurret.CoutDowLatch;@RuWith(SprigRuer.class)@SprigBootTestpublicclassQmqTest{ @Resource privateQmqTemplatetemplate; @Resource privateQmqPropertiesproperties; /** *发送即时消息 *@throwsIterruptedExceptio */ @Test publicvoidsedImmediate()throwsIterruptedExceptio{ //计数器,执行1次结束 CoutDowLatchlatch=ewCoutDowLatch(1); //一般使用template.sed(properties.getSubject().get("sub1"),getUser())即可 template.withSedStateListeer(ewMessageSedStateListeer(){ @Override publicvoidoSuccess(Messagem){ latch.coutDow(); } @Override publicvoidoFailed(Messagem){ latch.coutDow(); } }).sed(properties.getSubject().get("sub1"),getUser()); //计数器减1 latch.await(); } /** *发送延时消息 *@throwsIterruptedExceptio */ @Test publicvoidsedDelay()throwsIterruptedExceptio{ //计数器,执行1次结束 CoutDowLatchlatch=ewCoutDowLatch(1); //延时10秒发送消息 //一般使用template.sedDelay(properties.getSubject().get("sub1"),getUser(),QmqTimeUit.TEN_SECONDS)即可 template.withSedStateListeer(ewMessageSedStateListeer(){ @Override publicvoidoSuccess(Messagem){ latch.coutDow(); } @Override publicvoidoFailed(Messagem){ latch.coutDow(); } }).sedDelay(properties.getSubject().get("sub1"),getUser(),QmqTimeUit.TEN_SECONDS); //计数器减1 latch.await(); } /** *发送定时消息 *@throwsIterruptedExceptio */ @Test publicvoidsedSchedule()throwsIterruptedExceptio,ParseExceptio{ //计数器,执行1次结束 CoutDowLatchlatch=ewCoutDowLatch(1); //定时发送的日期时间 Datedate=ewSimpleDateFormat("yyyy-MM-ddHH
点击空白处退出提示
评论