rocketmq 动态设置topic和consumerGroup


 1 @Override
 2 public void afterPropertiesSet() throws Exception {
 3     final RocketMQMessageListener annotation = MyConsumer.class.getAnnotation(RocketMQMessageListener.class);
 4     InvocationHandler h = Proxy.getInvocationHandler(annotation);
 5     Field hField = h.getClass().getDeclaredField("memberValues");
 6     hField.setAccessible(true);
 7     Map memberValues = (Map) hField.get(h);
 8     memberValues.put("topic", topic);
 9     memberValues.put("consumerGroup", consumerGroup);
10 }
11 此时 topic  consumerGroup 就可以通过配置中心或者文件来动态配置
12 比如:
13 @Value("${dynamic.spring.rocketmq.topic}"
14 private String topic

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM