|
@@ -2,12 +2,12 @@ package com.chelvc.framework.redis.config;
|
|
|
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.time.Duration;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
import com.chelvc.framework.common.util.AssertUtils;
|
|
|
import com.chelvc.framework.common.util.JacksonUtils;
|
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
+import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.redis.annotation.RedisMQConsumer;
|
|
|
import com.chelvc.framework.redis.stream.DefaultRedisMQListenerContainer;
|
|
|
import com.chelvc.framework.redis.stream.RedisMQListener;
|
|
@@ -27,14 +27,14 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.aop.framework.AopProxyUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.ApplicationArguments;
|
|
|
-import org.springframework.boot.ApplicationRunner;
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
|
|
+import org.springframework.boot.context.event.ApplicationStartedEvent;
|
|
|
import org.springframework.cache.CacheManager;
|
|
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
|
import org.springframework.cache.interceptor.KeyGenerator;
|
|
|
+import org.springframework.context.ApplicationListener;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.core.task.TaskExecutor;
|
|
@@ -60,11 +60,10 @@ import org.springframework.stereotype.Component;
|
|
|
@EnableCaching
|
|
|
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
-public class RedisConfigurer extends CachingConfigurerSupport implements ApplicationRunner {
|
|
|
+public class RedisConfigurer extends CachingConfigurerSupport implements ApplicationListener<ApplicationStartedEvent> {
|
|
|
private final TaskExecutor executor;
|
|
|
private final ClientResources clientResources;
|
|
|
private final LettuceConnectionFactory connectionFactory;
|
|
|
- private final AtomicInteger counter = new AtomicInteger(0);
|
|
|
|
|
|
/**
|
|
|
* 注册消息监听器容器
|
|
@@ -81,7 +80,7 @@ public class RedisConfigurer extends CachingConfigurerSupport implements Applica
|
|
|
);
|
|
|
Type type = ObjectUtils.lookupSuperclassParameterized(clazz, RedisMQListener.class, Object.class);
|
|
|
RedisMQListenerContainer<T> container = ApplicationContextHolder.register(
|
|
|
- this.counter.incrementAndGet(), RedisMQListenerContainer.class, DefaultRedisMQListenerContainer::new
|
|
|
+ StringUtils.uuid(), RedisMQListenerContainer.class, DefaultRedisMQListenerContainer::new
|
|
|
);
|
|
|
try {
|
|
|
container.initialize(type, listener, annotation);
|
|
@@ -92,7 +91,7 @@ public class RedisConfigurer extends CachingConfigurerSupport implements Applica
|
|
|
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public void run(ApplicationArguments args) throws Exception {
|
|
|
+ public void onApplicationEvent(ApplicationStartedEvent event) {
|
|
|
// Redis事件配置
|
|
|
EventBus bus = this.clientResources.eventBus();
|
|
|
ApplicationContextHolder.getBeans(RedisEventConfigurerAdapter.class).forEach(
|