use of com.jeesuite.amqp.qcloud.cmq.CMQConsumerAdapter in project jeesuite-libs by vakinge.
the class MQServiceRegistryBean method startConsumer.
private void startConsumer(String providerName) throws Exception {
Map<String, MessageHandler> messageHanlders = applicationContext.getBeansOfType(MessageHandler.class);
if (messageHanlders != null && !messageHanlders.isEmpty()) {
Map<String, MessageHandler> messageHandlerMaps = new HashMap<>();
messageHanlders.values().forEach(e -> {
Object origin = e;
try {
origin = SpringAopHelper.getTarget(e);
} catch (Exception ex) {
ex.printStackTrace();
}
MQTopicRef topicRef = origin.getClass().getAnnotation(MQTopicRef.class);
String topicName = MQContext.rebuildWithNamespace(topicRef.value());
messageHandlerMaps.put(topicName, e);
logger.info("ADD MQ_COMSUMER_HANDLER ->topic:{},handlerClass:{} ", topicName, e.getClass().getName());
});
if ("rocketmq".equals(providerName)) {
consumer = new RocketmqConsumerAdapter(messageHandlerMaps);
} else if ("cmq".equals(providerName)) {
consumer = new CMQConsumerAdapter(messageHandlerMaps);
} else if ("memoryqueue".equals(providerName)) {
MemoryQueueProducerAdapter.setMessageHandlers(messageHandlerMaps);
} else {
throw new JeesuiteBaseException("NOT_SUPPORT[providerName]:" + providerName);
}
consumer.start();
logger.info("MQ_COMSUMER started -> groupName:{},providerName:{}", MQContext.getGroupName(), providerName);
}
}
Aggregations