|
@ -34,39 +34,54 @@ public class RedisThread implements Runnable {
|
|
|
private PrescriptionService prescriptionService;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
//redis链接池
|
|
|
private JedisPool pool;
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
|
|
|
|
|
|
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
|
|
poolConfig.setMaxIdle(8);
|
|
|
poolConfig.setMaxTotal(8);
|
|
|
poolConfig.setMaxWaitMillis(-1);
|
|
|
poolConfig.setMinIdle(1);
|
|
|
JedisPool pool = null;
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
pool = new JedisPool(poolConfig,host,port,100000,password);
|
|
|
}else {
|
|
|
pool = new JedisPool(poolConfig,host,port,100000);
|
|
|
}
|
|
|
//初始化链接池
|
|
|
initPool();
|
|
|
|
|
|
while (true){
|
|
|
try {
|
|
|
Jedis jedis = pool.getResource();
|
|
|
String message = jedis.rpop(key);
|
|
|
if(StringUtils.isEmpty(message)){
|
|
|
Thread.sleep(1000L);//如果没有读取到记录,等待1秒
|
|
|
sleep(1000L);//如果没有读取到记录,等待1秒
|
|
|
}else {
|
|
|
redisMessage(message);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.info(e.getMessage());
|
|
|
sleep(5000L);
|
|
|
initPool();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void sleep(Long time){
|
|
|
try {
|
|
|
Thread.sleep(time);
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void initPool(){
|
|
|
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
|
|
poolConfig.setMaxIdle(8);
|
|
|
poolConfig.setMaxTotal(8);
|
|
|
poolConfig.setMaxWaitMillis(-1);
|
|
|
poolConfig.setMinIdle(1);
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
pool = new JedisPool(poolConfig,host,port,100000,password);
|
|
|
}else {
|
|
|
pool = new JedisPool(poolConfig,host,port,100000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void redisMessage(String message){
|
|
|
logger.info("redis_onMessage...:"+message);
|
|
|
//this.unsubscribe();
|