now mqtt reconnect will resub topic
This commit is contained in:
@@ -26,14 +26,12 @@ public class SimApiBaseController : Controller
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
public override void OnActionExecuting(ActionExecutingContext context)
|
public override void OnActionExecuting(ActionExecutingContext context)
|
||||||
{
|
{
|
||||||
if (!context.ModelState.IsValid)
|
if (context.ModelState.IsValid) return;
|
||||||
|
foreach (var item in context.ModelState.Values.Where(item =>
|
||||||
|
item.ValidationState == ModelValidationState.Invalid))
|
||||||
{
|
{
|
||||||
foreach (var item in context.ModelState.Values.Where(item =>
|
Error(400, item.Errors.First().ErrorMessage);
|
||||||
item.ValidationState == ModelValidationState.Invalid))
|
break;
|
||||||
{
|
|
||||||
Error(400, item.Errors.First().ErrorMessage);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-39
@@ -41,45 +41,8 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
|||||||
Options.SysName, Options.AppName, Options.AppId);
|
Options.SysName, Options.AppName, Options.AppId);
|
||||||
CreateConnection();
|
CreateConnection();
|
||||||
ProcessAttribute();
|
ProcessAttribute();
|
||||||
//事件客户端
|
|
||||||
if (Options.DisableEventClient)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Synapse Event Client Disabled: DisableEventClient set true");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.LogInformation("Synapse Event Client Ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
//RPC客户端
|
|
||||||
if (Options.DisableRpcClient)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Synapse Rpc Client Disabled: DisableEventClient set true");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RunRpcClient();
|
|
||||||
logger.LogInformation("Synapse Rpc Client Ready, Client Timeout: {OptionsRpcTimeout}s", Options.RpcTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RpcRegistry.Count > 0)
|
|
||||||
{
|
|
||||||
RunRpcServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EventRegistry.Count > 0)
|
|
||||||
{
|
|
||||||
RunEventServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Options.EnableConfigStore)
|
|
||||||
{
|
|
||||||
RunConfigStoreServer();
|
|
||||||
logger.LogInformation("Synapse Config Store Ready [{SysName}] ...", Options.SysName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 调用RPC使用明确的返回值类型
|
/// 调用RPC使用明确的返回值类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -165,13 +128,49 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
|||||||
Client.ConnectedAsync += _ =>
|
Client.ConnectedAsync += _ =>
|
||||||
{
|
{
|
||||||
logger.LogInformation("Synapse MQTT[{AppName}:{AppId}] 连接成功...", Options.AppName, Options.AppId);
|
logger.LogInformation("Synapse MQTT[{AppName}:{AppId}] 连接成功...", Options.AppName, Options.AppId);
|
||||||
|
//事件客户端
|
||||||
|
if (Options.DisableEventClient)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Synapse Event Client Disabled: DisableEventClient set true");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogInformation("Synapse Event Client Ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
//RPC客户端
|
||||||
|
if (Options.DisableRpcClient)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Synapse Rpc Client Disabled: DisableEventClient set true");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RunRpcClient();
|
||||||
|
logger.LogInformation("Synapse Rpc Client Ready, Client Timeout: {OptionsRpcTimeout}s", Options.RpcTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RpcRegistry.Count > 0)
|
||||||
|
{
|
||||||
|
RunRpcServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EventRegistry.Count > 0)
|
||||||
|
{
|
||||||
|
RunEventServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Options.EnableConfigStore)
|
||||||
|
{
|
||||||
|
RunConfigStoreServer();
|
||||||
|
logger.LogInformation("Synapse Config Store Ready [{SysName}] ...", Options.SysName);
|
||||||
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
//重连
|
//重连
|
||||||
Client.DisconnectedAsync += async _ =>
|
Client.DisconnectedAsync += async _ =>
|
||||||
{
|
{
|
||||||
logger.LogError("Synapse MQTT[{AppName}:{AppId}] 断开连接,开始重连...", Options.AppName, Options.AppId);
|
logger.LogError("Synapse MQTT[{AppName}:{AppId}] 断开连接,开始重连...", Options.AppName, Options.AppId);
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.LogInformation("Synapse MQTT[{AppName}:{AppId}] 开始连接MQTT服务器...", Options.AppName, Options.AppId);
|
logger.LogInformation("Synapse MQTT[{AppName}:{AppId}] 开始连接MQTT服务器...", Options.AppName, Options.AppId);
|
||||||
@@ -213,7 +212,7 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
|||||||
|
|
||||||
var callClass = sp.CreateScope().ServiceProvider.GetRequiredService(tmp.Class!);
|
var callClass = sp.CreateScope().ServiceProvider.GetRequiredService(tmp.Class!);
|
||||||
var mt = callClass.GetType().GetMethod(tmp.Method);
|
var mt = callClass.GetType().GetMethod(tmp.Method);
|
||||||
if (mt!.GetParameters().Length > 2 || mt.GetParameters().Length<1)
|
if (mt!.GetParameters().Length > 2 || mt.GetParameters().Length < 1)
|
||||||
{
|
{
|
||||||
logger.LogError(
|
logger.LogError(
|
||||||
"Synapse Event Register Error: Only one or two parameter supported. {Key} -> {Method}@{Class}",
|
"Synapse Event Register Error: Only one or two parameter supported. {Key} -> {Method}@{Class}",
|
||||||
|
|||||||
Reference in New Issue
Block a user