主要是监听器搞了俩次,需要先移除全部的监听器,仅仅添加一个监听器,那么就只会执行一次了
@Autowired
private RedissonClient redissonClient;
@Override
public void redisPubSubFlush() {
RTopic rTopic = redissonClient.getTopic(FLUSH_TOPIC_NAME);
rTopic.publish(FLUSH_TOPIC_NAME);
rTopic.removeAllListeners();
rTopic.addListener(new FlushMapReceiver());
// rTopic.addListener(String.class,new FlushMapReceiver());
log.error("#RedisFlushServiceImpl#redisPubSubFlush()本地缓存刷新发布订阅调用完成!");
}
@Override
public void redisPubSubFlushHwAutoEvaluationConfigMap() {
RTopic rTopic = redissonClient.getTopic(FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES);
rTopic.publish(FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES);
rTopic.removeAllListeners();
rTopic.addListener(new FlushAutoElevationMapReceiver());
log.error("#RedisFlushServiceImpl#redisPubSubFlushHwAutoEvaluationConfigMap()本地缓存刷新发布订阅新规则配置管理调用完成!");
}
其实这个有俩个监听器实现监听的
@Component
@Slf4j
public class FlushAutoElevationMapReceiver implements MessageListener {
private final static String FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES = "FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES";
@Override
public void onMessage(CharSequence channel, Object msg) {
if (Objects.equals(FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES, msg)) {
RedisFlushService redisFlushService = SpringContextUtils.getBean(RedisFlushService.class);
redisFlushService.flushHwAutoEvaluationConfigMap();
log.error("redis发布订阅【FLUSH_TOPIC_AUTO_EVALUATION_CONFIG_VALUES】触发刷新新规则配置项的本地缓存完成!");
}
}
}
@Component
@Slf4j
public class FlushMapReceiver implements MessageListener {
private final static String FLUSH_TOPIC_NAME = "FLUSH_TOPIC_NAME";
@Override
public void onMessage(CharSequence channel, Object msg) {
if (Objects.equals(FLUSH_TOPIC_NAME, msg)) {
RedisFlushService redisFlushService = SpringContextUtils.getBean(RedisFlushService.class);
redisFlushService.redisFlush();
log.error("redis发布订阅【FLUSH_TOPIC_NAME】触发刷新全量的本地缓存完成!");
}
}
}