Search in sources :

Example 1 with MqConsumer

use of com.fanxb.bookmark.common.annotation.MqConsumer in project bookmark by FleyX.

the class MqConfiguration method run.

@Override
public void run(ApplicationArguments args) {
    Map<String, Object> map = context.getBeansWithAnnotation(MqConsumer.class);
    map.values().forEach(item -> {
        if (!(item instanceof RedisConsumer)) {
            log.warn("注意检测到被@EsConsumer注解的类{}未实现RedisConsumer接口", item.getClass().getCanonicalName());
            return;
        }
        MqConsumer[] annotations = item.getClass().getAnnotationsByType(MqConsumer.class);
        MqConsumer annotation = annotations[0];
        topicMap.computeIfAbsent(annotation.value(), k -> new ArrayList<>()).add((RedisConsumer) item);
    });
    log.info("redis订阅信息汇总完毕!!!!!!");
    // 由一个线程始终循环获取es队列数据
    threadPoolExecutor.execute(loop());
}
Also used : ApplicationArguments(org.springframework.boot.ApplicationArguments) ApplicationRunner(org.springframework.boot.ApplicationRunner) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) MqConsumer(com.fanxb.bookmark.common.annotation.MqConsumer) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RedisConsumer(com.fanxb.bookmark.common.entity.redis.RedisConsumer) DisposableBean(org.springframework.beans.factory.DisposableBean) Map(java.util.Map) ThreadPoolFactory(com.fanxb.bookmark.common.factory.ThreadPoolFactory) RedisUtil(com.fanxb.bookmark.common.util.RedisUtil) MqConsumer(com.fanxb.bookmark.common.annotation.MqConsumer) RedisConsumer(com.fanxb.bookmark.common.entity.redis.RedisConsumer) ArrayList(java.util.ArrayList)

Aggregations

MqConsumer (com.fanxb.bookmark.common.annotation.MqConsumer)1 RedisConsumer (com.fanxb.bookmark.common.entity.redis.RedisConsumer)1 ThreadPoolFactory (com.fanxb.bookmark.common.factory.ThreadPoolFactory)1 RedisUtil (com.fanxb.bookmark.common.util.RedisUtil)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DisposableBean (org.springframework.beans.factory.DisposableBean)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ApplicationArguments (org.springframework.boot.ApplicationArguments)1 ApplicationRunner (org.springframework.boot.ApplicationRunner)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Component (org.springframework.stereotype.Component)1