!6 优化云快充ByteBuf

* 优化云快充ByteBuf
This commit is contained in:
三丙
2025-03-24 02:58:11 +00:00
parent f8baacdc38
commit d326a41963
16 changed files with 146 additions and 119 deletions

View File

@@ -64,27 +64,36 @@ public class DefaultPileProtocolService implements PileProtocolService {
DownlinkRequestMessage.Builder downlinkMessageBuilder = createDownlinkMessageBuilder(uplinkQueueMessage, loginRequest.getPileCode());
downlinkMessageBuilder.setDownlinkCmd(DownlinkCmdEnum.LOGIN_ACK.name());
if (pile != null) {
// 保存到缓存
cacheSession(uplinkQueueMessage, pile,
PileSession pileSession = createSession(uplinkQueueMessage, pile,
loginRequest.getRemoteAddress(),
loginRequest.getNodeId(),
loginRequest.getNodeHostAddress(),
loginRequest.getNodeRestPort(),
loginRequest.getNodeGrpcPort());
// 保存到缓存
pileSessionCache.put(new PileSessionCacheKey(pile.getPileCode()), pileSession);
downlinkMessageBuilder.setLoginResponse(LoginResponse.newBuilder()
.setSuccess(true)
.setPileCode(loginRequest.getPileCode())
.build());
downlinkCallService.sendDownlinkMessage(downlinkMessageBuilder, pileCode);
} else {
downlinkMessageBuilder.setLoginResponse(LoginResponse.newBuilder()
.setSuccess(false)
.setPileCode(loginRequest.getPileCode())
.build());
downlinkCallService.sendDownlinkMessage(downlinkMessageBuilder, uplinkQueueMessage, loginRequest);
}
downlinkCallService.sendDownlinkMessage(downlinkMessageBuilder, pileCode);
callback.onSuccess();
}
@@ -99,7 +108,7 @@ public class DefaultPileProtocolService implements PileProtocolService {
if (pile != null) {
// 重新保存到缓存
cacheSession(uplinkQueueMessage, pile,
createSession(uplinkQueueMessage, pile,
heartBeatRequest.getRemoteAddress(),
heartBeatRequest.getNodeId(),
heartBeatRequest.getNodeHostAddress(),
@@ -110,13 +119,13 @@ public class DefaultPileProtocolService implements PileProtocolService {
callback.onSuccess();
}
private void cacheSession(UplinkQueueMessage uplinkQueueMessage,
Pile pile,
String remoteAddress,
String nodeId,
String nodeIp,
int restPort,
int grpcPort) {
private PileSession createSession(UplinkQueueMessage uplinkQueueMessage,
Pile pile,
String remoteAddress,
String nodeId,
String nodeIp,
int restPort,
int grpcPort) {
PileSession pileSession = new PileSession(pile.getId(), pile.getPileCode(), uplinkQueueMessage.getProtocolName());
pileSession.setProtocolSessionId(new UUID(uplinkQueueMessage.getSessionIdMSB(), uplinkQueueMessage.getSessionIdLSB()));
pileSession.setRemoteAddress(remoteAddress);
@@ -124,7 +133,8 @@ public class DefaultPileProtocolService implements PileProtocolService {
pileSession.setNodeIp(nodeIp);
pileSession.setNodeRestPort(restPort);
pileSession.setNodeGrpcPort(grpcPort);
pileSessionCache.put(new PileSessionCacheKey(pile.getPileCode()), pileSession);
return pileSession;
}
@Override

View File

@@ -11,7 +11,6 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import sanbing.jcpp.app.data.PileSession;
import sanbing.jcpp.app.service.DownlinkCallService;
import sanbing.jcpp.app.service.grpc.DownlinkGrpcClient;
import sanbing.jcpp.proto.gen.ProtocolProto.DownlinkRequestMessage;
@@ -31,7 +30,7 @@ public class GrpcDownlinkCallService extends DownlinkCallService {
DownlinkGrpcClient downlinkGrpcClient;
@Override
protected void _sendDownlinkMessage(DownlinkRequestMessage downlinkMessage, PileSession pileSession) {
protected void _sendDownlinkMessage(DownlinkRequestMessage downlinkMessage, String nodeIp, int nodeRestPort, int nodeGrpcPort) {
try {
RequestMsg requestMsg = RequestMsg.newBuilder()
@@ -40,7 +39,7 @@ public class GrpcDownlinkCallService extends DownlinkCallService {
.setDownlinkRequestMessage(downlinkMessage)
.build();
downlinkGrpcClient.sendDownlinkRequest(HostAndPort.fromParts(pileSession.getNodeIp(), pileSession.getNodeGrpcPort()),
downlinkGrpcClient.sendDownlinkRequest(HostAndPort.fromParts(nodeIp, nodeGrpcPort),
requestMsg);
} catch (Exception e) {

View File

@@ -16,7 +16,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import sanbing.jcpp.app.data.PileSession;
import sanbing.jcpp.app.service.DownlinkCallService;
import sanbing.jcpp.infrastructure.util.trace.TracerContextUtil;
import sanbing.jcpp.proto.gen.ProtocolProto.DownlinkRequestMessage;
@@ -35,10 +34,10 @@ public class RestDownlinkCallService extends DownlinkCallService {
RestTemplate downlinkRestTemplate;
@Override
protected void _sendDownlinkMessage(DownlinkRequestMessage downlinkMessage, PileSession pileSession) {
protected void _sendDownlinkMessage(DownlinkRequestMessage downlinkMessage, String nodeIp, int nodeRestPort, int nodeGrpcPort) {
try {
invokeDownlinkRestApi(downlinkMessage, pileSession.getNodeIp(), pileSession.getNodeRestPort());
invokeDownlinkRestApi(downlinkMessage, nodeIp, nodeGrpcPort);
} catch (RestClientException e) {
log.error("下行消息发送异常", e);