我正在尝试侦听redis集群的不同节点中的过期事件。redis集群有3个主节点。由于某些原因,应用程序只订阅了一个随机redis节点。我找到了以下线程,但解决方法是侦听所有主节点。我也尝试过绝Map书馆。如何强制spring配置侦听所有节点?这是我当前的配置:
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(Arrays.asList("172.18.0.2:6379,172.18.0.3:6379,172.18.0.4:6379".split(",")));
clusterConfiguration.setMaxRedirects(10000);
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(clusterConfiguration);
return lettuceConnectionFactory;
}
@Bean
RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory, @Qualifier("expirationListenerAdapter") MessageListenerAdapter expirationListenerAdapter) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(redisConnectionFactory);
container.addMessageListener(expirationListenerAdapter, new PatternTopic("__keyevent@*__:expired"));
return container;
}
@Bean("expirationListenerAdapter")
MessageListenerAdapter expirationListenerAdapter(RedisReceiver redisReceiver) {
return new MessageListenerAdapter(ListenerClass, "expiredEvent");
}
@Bean
ListenerClass receiver() {
return new ListenerClass();
}
暂无答案!
目前还没有任何答案,快来回答吧!