Search in sources :

Example 1 with CMQConsumerAdapter

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);
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) HashMap(java.util.HashMap) CMQConsumerAdapter(com.jeesuite.amqp.qcloud.cmq.CMQConsumerAdapter) RocketmqConsumerAdapter(com.jeesuite.amqp.rocketmq.RocketmqConsumerAdapter) BeansException(org.springframework.beans.BeansException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

CMQConsumerAdapter (com.jeesuite.amqp.qcloud.cmq.CMQConsumerAdapter)1 RocketmqConsumerAdapter (com.jeesuite.amqp.rocketmq.RocketmqConsumerAdapter)1 JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)1 HashMap (java.util.HashMap)1 BeansException (org.springframework.beans.BeansException)1