RocketMQ阿里云版整合springboot简单使用

SpringBoot整合RocketMQ(商业云端版)——发送普通消息

  1. 首先去阿里云控制台获取相关的资源,如topic、groupId、以及鉴权需要的AccessKet.
  2. 在springboot项目的pom.xml中添加以来
            <!-- RocketMQ -->
            <dependency>
                <groupId>com.aliyun.openservices</groupId>
                <artifactId>ons-client</artifactId>
                <version>1.8.4.Final</version>
            </dependency>
  3.  配置application配置文件
    #RocketMQ 将xxxxx替换为你的资源
    rocketmq.accessKey=xxxxx
    rocketmq.secretKey=xxxxx
    rocketmq.nameSrvAddr=http://xxxxx:8080
    rocketmq.topic=xxxxx
    rocketmq.groupId=xxxxx
    rocketmq.tag=*
  4. 封装MQ配置类 
    @Configuration
    @ConfigurationProperties(prefix = "rocketmq")
    public class MqConfig {
    
        private String accessKey;
        private String secretKey;
        private String nameSrvAddr;
    
        public Properties getMqPropertie() {
            Properties properties = new Properties();
            properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
            properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
            properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);
            return properties;
        }
    
        public String getAccessKey() {
            return accessKey;
        }
        public void setAccessKey(String accessKey) {
            this.accessKey = accessKey;
        }
        public String getSecretKey() {
            return secretKey;
        }
        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
      
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贰拾_陆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值