Authored by wangnan

优化mqlinster代码结构,减少重复代码

@@ -54,7 +54,7 @@ public abstract class AbstractMqListener implements ApplicationEventPublisherAwa @@ -54,7 +54,7 @@ public abstract class AbstractMqListener implements ApplicationEventPublisherAwa
54 54
55 public void dispatch(AbstractMqListener abstractMqListener, Message message) { 55 public void dispatch(AbstractMqListener abstractMqListener, Message message) {
56 try { 56 try {
57 - logger.info("===================Increase Begin=============================="); 57 + logger.info("==============================Increase Begin=========================================");
58 final String key = UUID.randomUUID().toString(); 58 final String key = UUID.randomUUID().toString();
59 String messageString = new String(message.getBody(), "UTF-8"); 59 String messageString = new String(message.getBody(), "UTF-8");
60 logger.info("[listener={}][key={}][message={}]", abstractMqListener.getClass().getSimpleName(), key, messageString); 60 logger.info("[listener={}][key={}][message={}]", abstractMqListener.getClass().getSimpleName(), key, messageString);
@@ -67,7 +67,7 @@ public abstract class AbstractMqListener implements ApplicationEventPublisherAwa @@ -67,7 +67,7 @@ public abstract class AbstractMqListener implements ApplicationEventPublisherAwa
67 } else { 67 } else {
68 abstractMqListener.updateData(json.getObject("data", Map.class), abstractMqListener.getIndexName(), key); 68 abstractMqListener.updateData(json.getObject("data", Map.class), abstractMqListener.getIndexName(), key);
69 } 69 }
70 - logger.info("====================Increase Finish============================="); 70 + logger.info("==============================Increase Finish=========================================");
71 } catch (Exception e) { 71 } catch (Exception e) {
72 logger.error(e.getMessage()); 72 logger.error(e.getMessage());
73 } 73 }
@@ -47,7 +47,7 @@ public class PromotionInfoMqListener extends AbstractMqListener implements Chann @@ -47,7 +47,7 @@ public class PromotionInfoMqListener extends AbstractMqListener implements Chann
47 return; 47 return;
48 } 48 }
49 promotionInfoService.saveOrUpdate(promotionInfo); 49 promotionInfoService.saveOrUpdate(promotionInfo);
50 - logger.info("[func=updateData][step=success][tableName={}][id={}][cost={}ms]", "promotion_info", promotionInfo.getId(), (System.currentTimeMillis() - begin)); 50 + logger.info("[func=updateData][id={}][cost={}ms]",promotionInfo.getId(), (System.currentTimeMillis() - begin));
51 } 51 }
52 52
53 @Override 53 @Override
@@ -57,7 +57,7 @@ public class PromotionInfoMqListener extends AbstractMqListener implements Chann @@ -57,7 +57,7 @@ public class PromotionInfoMqListener extends AbstractMqListener implements Chann
57 } 57 }
58 long begin = System.currentTimeMillis(); 58 long begin = System.currentTimeMillis();
59 promotionInfoService.delete(Integer.valueOf(id)); 59 promotionInfoService.delete(Integer.valueOf(id));
60 - logger.info("[func=deleteData][step=success][tableName={}][id={}][cost={}ms]", "promotion_info", id, System.currentTimeMillis() - begin); 60 + logger.info("[func=deleteData][id={}][cost={}ms]",id, System.currentTimeMillis() - begin);
61 } 61 }
62 62
63 @Override 63 @Override
@@ -47,7 +47,7 @@ public class PromotionParamsMqListener extends AbstractMqListener implements Cha @@ -47,7 +47,7 @@ public class PromotionParamsMqListener extends AbstractMqListener implements Cha
47 return; 47 return;
48 } 48 }
49 promotionParamsService.saveOrUpdate(promotionParams); 49 promotionParamsService.saveOrUpdate(promotionParams);
50 - logger.info("[func=updateData][step=success][tableName={}][id={}][cost={}ms]", "promotion_params", promotionParams.getPromotionId(), (System.currentTimeMillis() - begin)); 50 + logger.info("[func=updateData][id={}][cost={}ms]", promotionParams.getPromotionId(), (System.currentTimeMillis() - begin));
51 } 51 }
52 52
53 @Override 53 @Override
@@ -57,7 +57,7 @@ public class PromotionParamsMqListener extends AbstractMqListener implements Cha @@ -57,7 +57,7 @@ public class PromotionParamsMqListener extends AbstractMqListener implements Cha
57 } 57 }
58 long begin = System.currentTimeMillis(); 58 long begin = System.currentTimeMillis();
59 promotionParamsService.delete(Integer.valueOf(id)); 59 promotionParamsService.delete(Integer.valueOf(id));
60 - logger.info("[func=deleteData][step=success][tableName={}][id={}][cost={}ms]", "promotion_params", id, System.currentTimeMillis() - begin); 60 + logger.info("[func=deleteData][id={}][cost={}ms]", id, System.currentTimeMillis() - begin);
61 } 61 }
62 62
63 @Override 63 @Override
@@ -57,7 +57,7 @@ public class ScoreRuleMqListener extends AbstractMqListener implements ChannelAw @@ -57,7 +57,7 @@ public class ScoreRuleMqListener extends AbstractMqListener implements ChannelAw
57 scoreRuleLogicService.tryUpdateFunctionScoreRule(scoreRule); 57 scoreRuleLogicService.tryUpdateFunctionScoreRule(scoreRule);
58 // 更新数据库 58 // 更新数据库
59 scoreRuleService.saveOrUpdate(scoreRule); 59 scoreRuleService.saveOrUpdate(scoreRule);
60 - logger.info("[func=updateData][step=success][tableName={}][id={}][cost={}ms]", "score_rule", scoreRule.getId(), (System.currentTimeMillis() - begin)); 60 + logger.info("[func=updateData][id={}][cost={}ms]", scoreRule.getId(), (System.currentTimeMillis() - begin));
61 } 61 }
62 62
63 @Override 63 @Override
@@ -72,7 +72,7 @@ public class ScoreRuleMqListener extends AbstractMqListener implements ChannelAw @@ -72,7 +72,7 @@ public class ScoreRuleMqListener extends AbstractMqListener implements ChannelAw
72 scoreRuleLogicService.tryRemoveFunctionScoreRule(sourceData.getRuleType()); 72 scoreRuleLogicService.tryRemoveFunctionScoreRule(sourceData.getRuleType());
73 // 删除数据 73 // 删除数据
74 scoreRuleService.delete(Integer.valueOf(id)); 74 scoreRuleService.delete(Integer.valueOf(id));
75 - logger.info("[func=deleteData][step=success][tableName={}][id={}][cost={}ms]", "score_rule", id, System.currentTimeMillis() - begin); 75 + logger.info("[func=deleteData][id={}][cost={}ms]", id, System.currentTimeMillis() - begin);
76 } 76 }
77 } 77 }
78 78
@@ -43,7 +43,6 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa @@ -43,7 +43,6 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa
43 process(this, message); 43 process(this, message);
44 long nowTimeMillis = System.currentTimeMillis(); 44 long nowTimeMillis = System.currentTimeMillis();
45 publisher.publishEvent(new SearchLogsEvent("MqListener", EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getMoudleName(), "monitor", nowTimeMillis + "")); 45 publisher.publishEvent(new SearchLogsEvent("MqListener", EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getMoudleName(), "monitor", nowTimeMillis + ""));
46 - // 记录上报的日志  
47 SEARCH_EVENT_LOG.info("report to influxDb,currentTimeMillis is [{}],EventName is [{}] ,MoudleName is [{}]", nowTimeMillis, "MqListener", "consumer"); 46 SEARCH_EVENT_LOG.info("report to influxDb,currentTimeMillis is [{}],EventName is [{}] ,MoudleName is [{}]", nowTimeMillis, "MqListener", "consumer");
48 } catch (Exception e) { 47 } catch (Exception e) {
49 publisher.publishEvent(new SearchEvent(EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getEventName(), EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getFunctionName(), 48 publisher.publishEvent(new SearchEvent(EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getEventName(), EventReportEnum.STANDARDMQLISTENER_ONMESSAGE.getFunctionName(),
@@ -53,6 +52,7 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa @@ -53,6 +52,7 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa
53 } 52 }
54 } 53 }
55 54
  55 + @Override
56 public void updateData(final Map data, final String indexName, final String key) { 56 public void updateData(final Map data, final String indexName, final String key) {
57 long begin = System.currentTimeMillis(); 57 long begin = System.currentTimeMillis();
58 Standard standard = new Standard(); 58 Standard standard = new Standard();
@@ -61,16 +61,17 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa @@ -61,16 +61,17 @@ public class StandardMqListener extends AbstractMqListener implements ChannelAwa
61 return; 61 return;
62 } 62 }
63 standardService.saveOrUpdate(standard); 63 standardService.saveOrUpdate(standard);
64 - logger.info("[func=updateData][step=success][tableName=standard][id={}][cost={}ms]", standard.getId(), (System.currentTimeMillis() - begin)); 64 + logger.info("[func=updateData][id={}][cost={}ms]", standard.getId(), (System.currentTimeMillis() - begin));
65 } 65 }
66 66
  67 + @Override
67 public void deleteData(final String id, final String indexName, final String key) { 68 public void deleteData(final String id, final String indexName, final String key) {
68 if (StringUtils.isBlank(id)) { 69 if (StringUtils.isBlank(id)) {
69 return; 70 return;
70 } 71 }
71 long begin = System.currentTimeMillis(); 72 long begin = System.currentTimeMillis();
72 standardService.delete(Integer.valueOf(id)); 73 standardService.delete(Integer.valueOf(id));
73 - logger.info("[func=deleteData][step=success][tableName=standard][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin)); 74 + logger.info("[func=deleteData][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin));
74 } 75 }
75 76
76 @Override 77 @Override