1
This commit is contained in:
parent
37103ea955
commit
9a6b5aaf18
@ -122,11 +122,10 @@ namespace YunDa.Server.ISMSTcp.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
// 记录消息处理开始
|
||||
var parsedMessageType = ISMSMessageTypeExtensions.ParseMessageType(messageType);
|
||||
//_logger.LogInformationWithFilter(_filterControlService, parsedMessageType,
|
||||
// "开始处理消息类型: {MessageType}", messageType);
|
||||
|
||||
if (messageType.ToUpper()!= "YC"&& messageType.ToUpper()!= "YX"&& "HeartBeat"!= messageType&& "CommState" != messageType)
|
||||
{
|
||||
Log.Information(messageType + ":" + originalJson);
|
||||
}
|
||||
// 触发TCP响应接收事件
|
||||
TcpResponseReceived?.Invoke();
|
||||
Models.ProcessResult result = messageType.ToUpper() switch
|
||||
|
||||
@ -447,7 +447,6 @@ namespace YunDa.Server.ISMSTcp.Services
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算延迟时间(指数退避算法)
|
||||
var delay = CalculateReconnectDelay(_reconnectAttempts);
|
||||
|
||||
_logger.LogInformation("Scheduling reconnect attempt #{Attempt} in {Delay} seconds",
|
||||
@ -461,16 +460,11 @@ namespace YunDa.Server.ISMSTcp.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算重连延迟时间(指数退避算法)
|
||||
/// 计算重连延迟时间(固定10秒)
|
||||
/// </summary>
|
||||
private TimeSpan CalculateReconnectDelay(int attemptCount)
|
||||
{
|
||||
// 指数退避:初始延迟1秒,最大延迟30秒
|
||||
var baseDelaySeconds = 1.0;
|
||||
var maxDelaySeconds = 30.0;
|
||||
|
||||
var delaySeconds = Math.Min(baseDelaySeconds * Math.Pow(2, attemptCount), maxDelaySeconds);
|
||||
return TimeSpan.FromSeconds(delaySeconds);
|
||||
return TimeSpan.FromSeconds(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -482,28 +476,6 @@ namespace YunDa.Server.ISMSTcp.Services
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否超过最大重连次数
|
||||
if (_reconnectAttempts >= _config.MaxRetries)
|
||||
{
|
||||
_logger.LogError("Maximum reconnection attempts ({MaxRetries}) reached. Stopping reconnection attempts.",
|
||||
_config.MaxRetries);
|
||||
|
||||
lock (_reconnectStateLock)
|
||||
{
|
||||
_reconnectTimer?.Dispose();
|
||||
_reconnectTimer = null;
|
||||
}
|
||||
|
||||
ConnectionStatusChanged?.Invoke(false, $"重连失败:已达到最大重连次数 {_config.MaxRetries}");
|
||||
return;
|
||||
}
|
||||
|
||||
_reconnectAttempts++;
|
||||
|
||||
_logger.LogInformation("Attempting reconnection #{Attempt}/{MaxRetries} to {IP}:{Port}",
|
||||
_reconnectAttempts, _config.MaxRetries, _lastConnectedIp, _lastConnectedPort);
|
||||
|
||||
try
|
||||
{
|
||||
await _reconnectLock.WaitAsync();
|
||||
@ -512,20 +484,10 @@ namespace YunDa.Server.ISMSTcp.Services
|
||||
|
||||
if (success)
|
||||
{
|
||||
// 重连成功,重置重连计数器
|
||||
_reconnectAttempts = 0;
|
||||
|
||||
lock (_reconnectStateLock)
|
||||
{
|
||||
_reconnectTimer?.Dispose();
|
||||
_reconnectTimer = null;
|
||||
}
|
||||
|
||||
StartHeartbeat();
|
||||
|
||||
_logger.LogInformation("Successfully reconnected to {IP}:{Port} after {Attempts} attempts",
|
||||
_lastConnectedIp, _lastConnectedPort, _reconnectAttempts);
|
||||
|
||||
ConnectionStatusChanged?.Invoke(true, "重连成功");
|
||||
}
|
||||
else
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
}
|
||||
},
|
||||
"ISMSServer": {
|
||||
"ServerIP": "192.168.81.229",
|
||||
"ServerIP": "192.168.81.21",
|
||||
"HeartbeatIntervalSeconds": 60,
|
||||
"AutoConnectDelaySeconds": 10
|
||||
},
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
}
|
||||
},
|
||||
"ISMSServer": {
|
||||
"ServerIP": "192.168.81.22",
|
||||
"ServerIP": "192.168.81.21",
|
||||
"ServerPort": 43916,
|
||||
"ReconnectDelaySeconds": 5,
|
||||
"MaxRetries": 50,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user