|
@ -3,6 +3,8 @@ package com.yihu.wlyy.redis;
|
|
|
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
|
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
@ -15,6 +17,7 @@ import redis.clients.jedis.Jedis;
|
|
|
@Component
|
|
|
public class RedisThread implements Runnable {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(RedisThread.class);
|
|
|
@Value("${channel.redis.host}")
|
|
|
private String url;
|
|
|
@Value("${channel.redis.port}")
|
|
@ -35,16 +38,18 @@ public class RedisThread implements Runnable {
|
|
|
jedis.auth(password);
|
|
|
}
|
|
|
while (true){
|
|
|
String message = jedis.rpop(key);
|
|
|
if(StringUtils.isEmpty(message)){
|
|
|
try{
|
|
|
try {
|
|
|
String message = jedis.rpop(key);
|
|
|
if(StringUtils.isEmpty(message)){
|
|
|
Thread.sleep(1000L);//如果没有读取到记录,等待1秒
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}else {
|
|
|
prescriptionService.redisMessage(message);
|
|
|
}
|
|
|
}else {
|
|
|
prescriptionService.redisMessage(message);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.info(e.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|