| 
					
				 | 
			
			
				@ -1,10 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.redis.core.StringRedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import redis.clients.jedis.Jedis; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Trick on 2017/8/7. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -16,9 +18,27 @@ public class RedisThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private RedisMsgPubSubListener redisMsgPubSubListener; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private StringRedisTemplate redisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionService prescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |