|
@ -1,10 +1,12 @@
|
|
package com.yihu.wlyy.redis;
|
|
package com.yihu.wlyy.redis;
|
|
|
|
|
|
|
|
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by Trick on 2017/8/7.
|
|
* Created by Trick on 2017/8/7.
|
|
@ -16,9 +18,27 @@ public class RedisThread implements Runnable {
|
|
private String url;
|
|
private String url;
|
|
@Autowired
|
|
@Autowired
|
|
private RedisMsgPubSubListener redisMsgPubSubListener;
|
|
private RedisMsgPubSubListener redisMsgPubSubListener;
|
|
|
|
@Autowired
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
@Autowired
|
|
|
|
private PrescriptionService prescriptionService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
Jedis jedis = new Jedis(url);
|
|
|
|
jedis.subscribe(redisMsgPubSubListener, SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title"));
|
|
|
|
|
|
String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
|
|
|
|
while (true){
|
|
|
|
redisTemplate.watch(key);
|
|
|
|
String message = redisTemplate.opsForList().rightPop(key);
|
|
|
|
redisTemplate.unwatch();
|
|
|
|
if(StringUtils.isEmpty(message)){
|
|
|
|
try{
|
|
|
|
Thread.sleep(1000L);//如果没有读取到记录,等待1秒
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
prescriptionService.redisMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|