diff --git a/Doc/星尘分布式.emmx b/Doc/星尘分布式.emmx index 755eb86f..cbfbde67 100644 Binary files a/Doc/星尘分布式.emmx and b/Doc/星尘分布式.emmx differ diff --git a/Doc/星尘分布式.png b/Doc/星尘分布式.png index ed13f4bb..cb17ff06 100644 Binary files a/Doc/星尘分布式.png and b/Doc/星尘分布式.png differ diff --git a/Doc/本地通信.emmx b/Doc/本地通信.emmx new file mode 100644 index 00000000..7a2dfcf6 Binary files /dev/null and b/Doc/本地通信.emmx differ diff --git a/StarAgent/StarService.cs b/StarAgent/StarService.cs index 0ca87da4..5096a298 100644 --- a/StarAgent/StarService.cs +++ b/StarAgent/StarService.cs @@ -92,6 +92,11 @@ public class StarService : DisposeBase, IApi return ai; } + public PingResponse Ping(AppInfo appInfo) + { + return null; + } + /// 设置星尘服务端地址 /// [Api(nameof(SetServer))] diff --git a/Stardust.Web/Areas/Registry/Controllers/AppMeterController.cs b/Stardust.Web/Areas/Registry/Controllers/AppMeterController.cs index 229e71f3..1ea9741e 100644 --- a/Stardust.Web/Areas/Registry/Controllers/AppMeterController.cs +++ b/Stardust.Web/Areas/Registry/Controllers/AppMeterController.cs @@ -112,7 +112,7 @@ public class AppMeterController : EntityController Title = new ChartTitle { Text = app.Name + "#" + clientId }, Height = 400, }; - chart.SetX(list2, _.CreateTime, e => e.CreateTime.ToString("HH:mm")); + chart.SetX(list2, _.Time, e => e.Time.ToString("HH:mm")); //chart.SetY("指标"); chart.YAxis = new[] { new { name = "指标", type = "value" }, diff --git a/Stardust/AppClient.cs b/Stardust/AppClient.cs index fe39f966..3a5b8947 100644 --- a/Stardust/AppClient.cs +++ b/Stardust/AppClient.cs @@ -11,8 +11,6 @@ using Stardust.Models; using Stardust.Registry; using Stardust.Services; using NewLife.Caching; -using System; -using System.Net.Http; #if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD using System.Net.WebSockets; using TaskEx = System.Threading.Tasks.Task; @@ -39,6 +37,9 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide /// WebSocket长连接。建立长连接后,可以实时感知配置更新和注册服务更新,默认false public Boolean UseWebSocket { get; set; } + /// 星尘工厂 + public StarFactory Factory { get; set; } + private ConcurrentDictionary _commands = new(StringComparer.OrdinalIgnoreCase); /// 命令集合 public IDictionary Commands => _commands; @@ -185,7 +186,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide /// 心跳 /// - public async Task Ping() + public async Task Ping() { try { @@ -194,7 +195,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide else _appInfo.Refresh(); - PingResponse rs = null; + PingResponse? rs = null; try { rs = await PostAsync("App/Ping", _appInfo); @@ -257,6 +258,17 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide } } + /// 向本地StarAgent发送心跳 + /// + /// + public async Task PingLocal(AppInfo? appInfo) + { + var local = Factory?.Local; + if (local == null || local.Info == null) return null; + + return await local.PingAsync(appInfo); + } + private TimeSpan _span; /// 获取相对于服务器的当前时间,避免两端时间差 /// @@ -391,7 +403,17 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide if (rs == null) return; } - await Ping(); + // 向服务端发送心跳后,再向本地发送心跳 + try + { + await Ping(); + await PingLocal(null); + } + catch + { + await PingLocal(_appInfo); + throw; + } await RefreshPublish(); await RefreshConsume(); diff --git a/Stardust/LocalStarClient.cs b/Stardust/LocalStarClient.cs index 37977937..8b62423a 100644 --- a/Stardust/LocalStarClient.cs +++ b/Stardust/LocalStarClient.cs @@ -113,6 +113,15 @@ public class LocalStarClient throw; } } + + /// 向StarAgent发送心跳 + /// + public async Task PingAsync(AppInfo? appInfo) + { + Init(); + + return await _client.InvokeAsync("Ping", appInfo); + } #endregion #region 进程控制 @@ -161,7 +170,11 @@ public class LocalStarClient var set = NewLife.Setting.Current; url = set.PluginServer.EnsureEnd("/"); url += "star/"; - if (Environment.Version.Major >= 6) + if (Environment.Version.Major >= 8) + url += "staragent80.zip"; + else if (Environment.Version.Major >= 7) + url += "staragent70.zip"; + else if (Environment.Version.Major >= 6) url += "staragent60.zip"; else if (Environment.Version.Major >= 5) url += "staragent50.zip"; diff --git a/Stardust/StarFactory.cs b/Stardust/StarFactory.cs index 0d22ddab..27980530 100644 --- a/Stardust/StarFactory.cs +++ b/Stardust/StarFactory.cs @@ -271,6 +271,7 @@ public class StarFactory : DisposeBase var client = new AppClient(Server) { + Factory = this, AppId = AppId, AppName = AppName, ClientId = ClientId,