Commit 78ca17eb53350e905355cad52c9174bb3103e639

Authored by fangcheng
1 parent 3b5188ac0c
Exists in master

错误队列添加

Showing 5 changed files with 84 additions and 6 deletions

parent/center.manager/src/main/java/com/lyms/cm/job/SyncTmpJob.java View file @ 78ca17e
1 1 package com.lyms.cm.job;
2 2  
  3 +import java.io.Serializable;
3 4 import java.util.concurrent.atomic.AtomicBoolean;
4 5  
5 6 import org.slf4j.Logger;
6 7 import org.slf4j.LoggerFactory;
7 8 import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.data.redis.core.RedisTemplate;
8 10  
  11 +import com.alibaba.fastjson.JSONObject;
9 12 import com.lyms.sync.SyncCallback;
10 13 import com.lyms.sync.SyncCenter;
11 14 import com.lyms.sync.SyncCenter.Work;
12 15 import com.lyms.sync.channel.ChannelData;
  16 +import com.lyms.sync.queue.SyncQueue;
13 17 import com.lyms.util.HttpUtils;
14 18 import com.lyms.util.JsonUtils;
15 19  
16 20  
... ... @@ -28,8 +32,20 @@
28 32  
29 33 @Autowired
30 34 public SyncCenter center;
  35 +
  36 + @Autowired
  37 + public RedisTemplate<Serializable, Serializable> template;
  38 +
  39 + /**
  40 + * 初始化的时候将错误队列内容迁移到临时任务队列
  41 + */
  42 + private static boolean initLoadErrorToTempWork = true;
31 43  
32 44 public void excute() {
  45 + if(initLoadErrorToTempWork){
  46 + errorWorkToTempWork();
  47 + }
  48 +
33 49 if (reset.get()) {
34 50 return;
35 51 }
... ... @@ -64,6 +80,34 @@
64 80 } finally {
65 81 reset.set(false);
66 82 }
  83 + }
  84 +
  85 +
  86 + /**
  87 + * <li>@Description:错误队列迁移到临时任务队列
  88 + * <li>
  89 + * <li>创建人:方承
  90 + * <li>创建时间:2017年5月5日
  91 + * <li>修改人:
  92 + * <li>修改时间:
  93 + */
  94 + public void errorWorkToTempWork(){
  95 + initLoadErrorToTempWork = false;
  96 + LOG.info("=============开始==迁移同步队列【错误队列 转移到 临时任务队列】============");
  97 + boolean hasNext = true;
  98 + while(hasNext){
  99 + Serializable object = template.opsForList().rightPop(SyncQueue.TMP_WORK_ERROR);
  100 + if(object != null){
  101 + ChannelData data = (ChannelData) object;
  102 + LOG.info(JSONObject.toJSONString(data));
  103 + data.setErrorRetryCount(0);
  104 + template.opsForList().leftPush(SyncQueue.TMP_WORK, data);
  105 + }else{
  106 + hasNext = false;
  107 + }
  108 + }
  109 + LOG.info("=============结束==迁移同步队列【错误队列 转移到 临时任务队列】============");
  110 + return;
67 111 }
68 112 }
parent/center.manager/src/main/resources/dev/redis.properties View file @ 78ca17e
1   -#redis.host1=119.90.57.26
2   -#redis.port1=6379
3   -#redis.password1=Lyms123456
4   -redis.host1=127.0.0.1
  1 +redis.host1=119.90.57.26
5 2 redis.port1=6379
6   -redis.password1=
  3 +redis.password1=Lyms123456
  4 +#redis.host1=127.0.0.1
  5 +#redis.port1=6379
  6 +#redis.password1=
7 7 #redis.host1=127.0.0.1
8 8 #redis.port1=6379
9 9 #redis.password1=Lyms123456
parent/core.sdk/src/main/java/com/lyms/sync/channel/ChannelData.java View file @ 78ca17e
... ... @@ -64,6 +64,11 @@
64 64 * 创建时间
65 65 */
66 66 private Long ts;
  67 +
  68 + /**
  69 + * 出错重试次数
  70 + */
  71 + private int errorRetryCount;
67 72  
68 73 public ChannelData(String remote, String remoteClazz, String remoteMethod, String data, boolean loop) {
69 74 this.id = StrUtils.uuid();
... ... @@ -166,6 +171,16 @@
166 171 public String toJsonString() {
167 172 return JsonUtils.beanToJson(this);
168 173 }
  174 +
  175 + public int getErrorRetryCount() {
  176 + return errorRetryCount;
  177 + }
  178 +
  179 + public void setErrorRetryCount(int errorRetryCount) {
  180 + this.errorRetryCount = errorRetryCount;
  181 + }
  182 +
  183 +
169 184  
170 185 }
parent/core.sdk/src/main/java/com/lyms/sync/queue/SyncQueue.java View file @ 78ca17e
... ... @@ -48,6 +48,17 @@
48 48 * 临时任务
49 49 */
50 50 public static final String TMP_WORK = "TMP_WORK";
  51 +
  52 + /**
  53 + * 错误重试次数
  54 + */
  55 + public static final int ERROR_RETRY_COUNT = 3;
  56 +
  57 +
  58 + /**
  59 + * 临时任务出错一定次数后放入此任务队列
  60 + */
  61 + public static final String TMP_WORK_ERROR = "TMP_WORK_ERROR";
51 62  
52 63 /**
53 64 * 回执消息任务
... ... @@ -112,7 +123,13 @@
112 123 * <li>修改时间:
113 124 */
114 125 private boolean pushTempWork(ChannelData data) {
115   - Long tag = template.opsForList().leftPush(TMP_WORK, data);
  126 + Long tag = 0l;
  127 + if(data.getErrorRetryCount() > ERROR_RETRY_COUNT){
  128 + tag = template.opsForList().leftPush(TMP_WORK_ERROR, data);
  129 + }else{
  130 + data.setErrorRetryCount(data.getErrorRetryCount() + 1);
  131 + tag = template.opsForList().leftPush(TMP_WORK, data);
  132 + }
116 133 return tag >= 1;
117 134 }
118 135  
parent/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java View file @ 78ca17e
... ... @@ -24,6 +24,7 @@
24 24 import com.lyms.base.common.service.role.PermissionsService;
25 25 import com.lyms.base.common.service.role.RolesService;
26 26 import com.lyms.base.common.service.user.UsersService;
  27 +import com.lyms.constants.Constants;
27 28 import com.lyms.hospital.service.token.TokenService;
28 29 import com.lyms.util.DateTimeUtils;
29 30 import com.lyms.util.InstanceUtils;
... ... @@ -141,6 +142,7 @@
141 142 result.put("watermark", "water");
142 143 ajaxResult.setData(result);
143 144 ajaxResult.setSuccess(true);
  145 + getSession().setAttribute(Constants.CURRENT_USER, users);
144 146 return ajaxResult;
145 147 }
146 148