我使用spring-redis publish-subscribe。它在开始运行我的代码时立即收到消息。但是大约几分钟后没有收到消息,它不会立即响应(不知道什么时候可以再次接收,几乎无法接收)!所以我想知道-是否有缓存设置或其他内容?
@Configuration
public class PubSubConfiguration {
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.addMessageListener(listenerAdapter, new PatternTopic("topic"));
return container;
}
/**
* @param receiver
* @return
*/
@Bean
MessageListenerAdapter listenerAdapter(Sub1 receiver) {
return new MessageListenerAdapter(receiver);
}
}
@Component
public class Pub1 {
@Autowired
private StringRedisTemplate stringRedisTemplate;
public void testCheckpoint() {
stringRedisTemplate.convertAndSend("topic", "2018-07-09");
System.out.println("sent...");
}
}
@Component
public class Sub1 implements MessageListener {
@Override
public void onMessage(final Message message, final byte[] pattern) {
String msg = new String(message.getBody());
String topic = new String(message.getChannel());
System.out.println(String.format("time: %s, msg: %s, topic: %s", LocalTime.now(), msg, topic));
}
}