添加忽略处理的消息列表。直接跳过不处理。减少error日志的误打

This commit is contained in:
zhouxiunai
2019-04-30 17:31:56 +08:00
parent 7230652b87
commit 3093fe69d0
5 changed files with 40 additions and 1 deletions
@@ -6,7 +6,9 @@ import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
import com.gzzn.omms.msgexchangeapi.entity.CminmsgWapper;
@@ -24,6 +26,9 @@ public class MsgHandlerDispatcher {
@Autowired
ICminmsgService cminmsgService;
@Value("${msgExchange.ignoreMsg}")
private String ignoreMsg;
public HandlerResult dispatch(Cminmsg cminmsg)
{
try
@@ -36,6 +41,11 @@ public class MsgHandlerDispatcher {
String type = msg.getMETA().getTYPE().name();
String subType = msg.getMETA().getSTYP().name();
if(!isNeedHandler(type,subType))
{
logger.error("消息type:{},subtype:{},设置不需要处理!",type,subType);
return HandlerResult.success();
}
Class clazzHandler = Class.forName(getHandlerClassName(type,subType));
Object classObject = clazzHandler.newInstance();
@@ -43,7 +53,6 @@ public class MsgHandlerDispatcher {
HandlerResult result = (HandlerResult) runMethod.invoke(classObject, cminmsgWapper);
return result;
} catch (Exception e) {
//throw new RuntimeException(e);
try
{
cminmsgService.updateBatchProcessed(Arrays.asList(cminmsg));//更新为已处理
@@ -76,4 +85,30 @@ public class MsgHandlerDispatcher {
return buffer.toString();
} //end function
/**
* 是否需要处理该消息
* @param type 消息主类型
* @param subType 消息子类型
* @return true 需要处理 ,false 不需要处理
*/
private boolean isNeedHandler(String type,String subType)
{
if(StringUtils.isEmpty(ignoreMsg))
{
return true;// 所有消息均需要处理
}
//
String typeToken = type + "-" + subType;
String typeTokenStar = type + "-*";
String ignoreMsgs[] = ignoreMsg.split(",");
for (String msg : ignoreMsgs) {
if(typeToken.equalsIgnoreCase(msg) || typeTokenStar.equalsIgnoreCase(msg))
{
return false; //不需要处理的消息逻辑
}
}
return true;
} //end function
}
+1
View File
@@ -55,6 +55,7 @@ kafka:
msgExchange:
intervalSeconds: 1
waitDateLeftOffset: 600000
ignoreMsg: ldm-*,regn-*,rsta-*,error-* #忽略的消息列表
logstash:
host: 130.120.3.234:5000
scheduled:
+1
View File
@@ -55,6 +55,7 @@ kafka:
msgExchange:
intervalSeconds: 1
waitDateLeftOffset: 600000
ignoreMsg: ldm-*,regn-*,rsta-*,error-* #忽略的消息列表
logstash:
host: 130.120.3.234:5000
scheduled:
+1
View File
@@ -55,6 +55,7 @@ kafka:
msgExchange:
intervalSeconds: 1
waitDateLeftOffset: 600000
ignoreMsg: ldm-*,regn-*,rsta-*,error-* #忽略的消息列表
logstash:
host: 172.17.35.160:5000
scheduled:
+1
View File
@@ -55,6 +55,7 @@ kafka:
msgExchange:
intervalSeconds: 1
waitDateLeftOffset: 600000
ignoreMsg: ldm-*,regn-*,rsta-*,error-* #忽略的消息列表
logstash:
host: 130.120.3.234:5000
scheduled: