阻止重复帧

This commit is contained in:
Guoqs
2024-10-28 14:29:51 +08:00
parent a590c8843b
commit f72feba8cc

View File

@@ -9,6 +9,7 @@ import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.CRC16Util;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.YKCUtils;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -91,9 +92,11 @@ public abstract class AbstractYkcHandler implements InitializingBean {
protected boolean verifyTheDuplicateRequest(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext ctx) {
// 获取序列号域
int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
// 获取帧类型
String frameTypeStr = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
// 获取channelId
String channelId = ctx.channel().id().asShortText();
String redisKey = "Request_" + channelId + "_" + serialNumber;
String redisKey = "Request_" + channelId + "_" + frameTypeStr;
Boolean result = redisCache.setnx(redisKey, ykcDataProtocol.getHEXString(), 30);
// result返回false说明没有设置成功就是说已经有相同请求了所以返回true重复
return !result;