MQ助手-是一个基于pulsar包自研实现的SpringBootStater。通过简单注解配置即可进行MQ消息生产与消费。
主要特性基于成熟pulsar包扩展,没有任何框架变动,只为简化开发使用配置简单灵活,无需复杂的配置文件:开发者可以快速注解类或者方法实现消息的生产与消费ApachePulsar云原生分布式消息流平台,当下最佳解决方案使用指引引入依赖implementation("cool.doudou:mq-assistant:latest")Pulsar配置pulsar:service-url:pulsar://127.0.0.1:6650subscription-name:sub-celerysubscription-type:Shared使用方式消息订阅生产者与topic进行关联绑定/***生产者主题绑定*/@MqProducer(topics={"celery"})@ComponentpublicclassMqComponent{}消费者与topic进行关联绑定,注意:每个消费者须绑定一个subscription-name后才能进行消费/***消费者主题绑定*/@ComponentpublicclassMqComponent{@MqConsumer(topics={"celery"})publicvoidreceive(Stringtopic,byte[]msg){System.out.println("consumer:topic["+topic+"]=>"+newString(msg));}}消息发送send():发送sendAsync():异步发送/***消息发送*/@AllArgsConstructor@ServicepublicclassMqServiceImpl{privateMqHelpermqHelper;publicvoidtest(){//同步StringmsgId=mqHelper.send("celery","hello");System.out.println("send:"+msgId);//异步mqHelper.sendAsync("celery","您好Async",System.out::println);//同步StringmsgId=mqHelper.send("celery",newbyte[]{0x01,0x02,0x03,0x04});System.out.println("send:"+msgId);//异步mqHelper.sendAsync("celery",newbyte[]{0x01,0x02,0x03,0x04},System.out::println);}}点击空白处退出提示
评论