在我的应用程序使用多个消费者接收来自redis发行商的消息。但现在的问题是数据丢失和重复数据我的意思是多个消费者接收reeving相同的消息。我在redis中解决这个问题?并且还可以提供java中的示例,它是redis messaging的新功能。请帮助我。数据丢失的情况下,多个消费者的redis消息
这里是我的接收机
@Configuration
@EnableScheduling
public class ScheduledRecevierService {
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Bean
RedisConnectionFactory redisConnectionFactory() {
LOGGER.info("in redisConnectionFactory");
JedisConnectionFactory redis = new JedisConnectionFactory();
redis.setHostName("ipaddress");
redis.setPort(6379);
return redis;
}
@Bean
StringRedisTemplate template(RedisConnectionFactory connectionFactory) {
LOGGER.info("in template");
return new StringRedisTemplate(connectionFactory);
}
@Scheduled(fixedRate = 1000)
public void getScheduledMessage() {
StringRedisTemplate template = template(redisConnectionFactory());
System.out.println("The time is now " + dateFormat.format(new Date()));
LOGGER.info("Sending messages...");
String message = template.opsForList().leftPop("point-to-point-test"); // latch.await();
// template.convertAndSend("chat", "Hello from Redis! count: " + i);
LOGGER.info("Got message " + message + " from chat1 channel"); //
}
}
我运行在多种消费instances.My队列这个应用程序的“点至点测试”有1000条短信是我观察到在多个服务器日志阅读相同的消息。
我们可以使用java在redis中实现点对点协议通信吗?
redis中的RPOPLPUSH命令解决了这个问题?如果是在java中发布一些示例。
从快速几天正在努力修复Redis的消息这些问题,请帮我
尝试显示自己的调查。 – 2014-10-01 07:52:13