当前位置:   article > 正文

Spring接入-阿里云RocketMQ_com.aliyun.openservices.ons

com.aliyun.openservices.ons

最近要接入rocketMQ,公司是在阿里云上买的rocketMQ服务,发现ALiYun rocketMQ 和通常的Apache rocketMQ 不太一样。看着阿里云的文档花了好长时间接入成功了。为了放便后续其他伙伴接入,就简单封装了一下。后续伙伴接入只需配一些必填的配置项就可以完成接入了。简单记录一下;

maven

  1. <dependency>
  2. <groupId>com.aliyun.openservices</groupId>
  3. <artifactId>ons-client</artifactId>
  4. <version>1.8.4.Final</version>
  5. </dependency>

client包源码: 

1、启动注解:

  1. @Documented
  2. @Target(ElementType.TYPE)
  3. @Retention(RetentionPolicy.RUNTIME)
  4. @Import({AliyunRocketMqAutoConfiguration.class, RocketMqProperties.class})
  5. public @interface EnableAliyunRocketMq {
  6. }

2、自动化配置Bean类 :

  1. /**
  2. * ALiYun-rocketMQ 接入配置
  3. *
  4. * @author zhangjiahui
  5. * @date 2020/12/15 3:48 下午
  6. */
  7. @Configuration
  8. public class AliyunRocketMqAutoConfiguration {
  9. @Autowired
  10. private RocketMqProperties rocketMqProperties;
  11. @Bean(destroyMethod = "shutdown")
  12. @ConditionalOnMissingBean({Producer.class})
  13. public Producer producer() {
  14. Producer producer = ONSFactory.createProducer(rocketMqProperties.getProperties());
  15. producer.start();
  16. return producer;
  17. }
  18. @Bean(destroyMethod = "shutdown")
  19. @ConditionalOnMissingBean({OrderProducer.class})
  20. public OrderProducer orderProducer() {
  21. OrderProducer orderProducer = ONSFactory.createOrderProducer(rocketMqProperties.getProperties());
  22. orderProducer.start();
  23. return orderProducer;
  24. }
  25. @Bean
  26. @ConditionalOnBean({Producer.class, OrderProducer.class})
  27. public AliyunRocketMqProducerHolder rocketMqProducerHolder(@Autowired Producer producer,
  28. @Autowired OrderProducer orderProducer) {
  29. AliyunRocketMqProducerHolder holder = AliyunRocketMqProducerHolder.getInstance();
  30. holder
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/386629
推荐阅读
相关标签
  

闽ICP备14008679号