Search in sources :

Example 1 with CMQConsumerAdapter

use of com.mendmix.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 if ("redis".equals(providerName)) {
            consumer = new RedisConsumerAdapter(redisTemplate, 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.mendmix.common.JeesuiteBaseException) HashMap(java.util.HashMap) CMQConsumerAdapter(com.mendmix.amqp.qcloud.cmq.CMQConsumerAdapter) RocketmqConsumerAdapter(com.mendmix.amqp.rocketmq.RocketmqConsumerAdapter) RedisConsumerAdapter(com.mendmix.amqp.redis.RedisConsumerAdapter) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) BeansException(org.springframework.beans.BeansException)

Aggregations

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