参考:
https://juejin.im/post/6844904150703013901
https://www.jianshu.com/p/106f0eae07c8
redis key失效通知实现延迟队列
redis.conf 增加配置
notify-keyspace-events Ex
@Bean
RedisMessageListenerContainer
container(@Qualifier("getConnectionFactory")
RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new
RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
return container;
}
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
@Override
public void onMessage(Message message, byte[] pattern) {
String expiredKey = message.toString();
System.out.println("监听***************************************************");
System.out.println("监听到key:" + expiredKey + "已过期");
System.out.println("监听***************************************************");
}
}
问题:消息通知不能持久化,出现宕机情况,消息丢失
rabbitMq的死信队列