Authored by wangnan

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

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