赞
踩
最近要接入rocketMQ,公司是在阿里云上买的rocketMQ服务,发现ALiYun rocketMQ 和通常的Apache rocketMQ 不太一样。看着阿里云的文档花了好长时间接入成功了。为了放便后续其他伙伴接入,就简单封装了一下。后续伙伴接入只需配一些必填的配置项就可以完成接入了。简单记录一下;
- <dependency>
- <groupId>com.aliyun.openservices</groupId>
- <artifactId>ons-client</artifactId>
- <version>1.8.4.Final</version>
- </dependency>
- @Documented
- @Target(ElementType.TYPE)
- @Retention(RetentionPolicy.RUNTIME)
- @Import({AliyunRocketMqAutoConfiguration.class, RocketMqProperties.class})
- public @interface EnableAliyunRocketMq {
- }
- /**
- * ALiYun-rocketMQ 接入配置
- *
- * @author zhangjiahui
- * @date 2020/12/15 3:48 下午
- */
- @Configuration
- public class AliyunRocketMqAutoConfiguration {
-
- @Autowired
- private RocketMqProperties rocketMqProperties;
-
- @Bean(destroyMethod = "shutdown")
- @ConditionalOnMissingBean({Producer.class})
- public Producer producer() {
- Producer producer = ONSFactory.createProducer(rocketMqProperties.getProperties());
- producer.start();
- return producer;
- }
-
- @Bean(destroyMethod = "shutdown")
- @ConditionalOnMissingBean({OrderProducer.class})
- public OrderProducer orderProducer() {
- OrderProducer orderProducer = ONSFactory.createOrderProducer(rocketMqProperties.getProperties());
- orderProducer.start();
- return orderProducer;
- }
-
-
- @Bean
- @ConditionalOnBean({Producer.class, OrderProducer.class})
- public AliyunRocketMqProducerHolder rocketMqProducerHolder(@Autowired Producer producer,
- @Autowired OrderProducer orderProducer) {
- AliyunRocketMqProducerHolder holder = AliyunRocketMqProducerHolder.getInstance();
- holder
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。