SpringBoot整合RocketMQ(商业云端版)——发送普通消息
- 首先去阿里云控制台获取相关的资源,如topic、groupId、以及鉴权需要的AccessKet.
- 在springboot项目的pom.xml中添加以来
<!-- RocketMQ --> <dependency> <groupId>com.aliyun.openservices</groupId> <artifactId>ons-client</artifactId> <version>1.8.4.Final</version> </dependency>
- 配置application配置文件
#RocketMQ 将xxxxx替换为你的资源 rocketmq.accessKey=xxxxx rocketmq.secretKey=xxxxx rocketmq.nameSrvAddr=http://xxxxx:8080 rocketmq.topic=xxxxx rocketmq.groupId=xxxxx rocketmq.tag=*
- 封装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; }