向服务端发送心跳后,再向本地发送心跳
This commit is contained in:
parent
364580a2f0
commit
01c5dc797f
BIN
Doc/星尘分布式.emmx
BIN
Doc/星尘分布式.emmx
Binary file not shown.
BIN
Doc/星尘分布式.png
BIN
Doc/星尘分布式.png
Binary file not shown.
Before Width: | Height: | Size: 763 KiB After Width: | Height: | Size: 815 KiB |
Binary file not shown.
|
@ -92,6 +92,11 @@ public class StarService : DisposeBase, IApi
|
|||
return ai;
|
||||
}
|
||||
|
||||
public PingResponse Ping(AppInfo appInfo)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>设置星尘服务端地址</summary>
|
||||
/// <returns></returns>
|
||||
[Api(nameof(SetServer))]
|
||||
|
|
|
@ -112,7 +112,7 @@ public class AppMeterController : EntityController<AppMeter>
|
|||
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" },
|
||||
|
|
|
@ -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
|
|||
/// <summary>WebSocket长连接。建立长连接后,可以实时感知配置更新和注册服务更新,默认false</summary>
|
||||
public Boolean UseWebSocket { get; set; }
|
||||
|
||||
/// <summary>星尘工厂</summary>
|
||||
public StarFactory Factory { get; set; }
|
||||
|
||||
private ConcurrentDictionary<String, Delegate> _commands = new(StringComparer.OrdinalIgnoreCase);
|
||||
/// <summary>命令集合</summary>
|
||||
public IDictionary<String, Delegate> Commands => _commands;
|
||||
|
@ -185,7 +186,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
|
|||
|
||||
/// <summary>心跳</summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Object> Ping()
|
||||
public async Task<Object?> 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<PingResponse>("App/Ping", _appInfo);
|
||||
|
@ -257,6 +258,17 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>向本地StarAgent发送心跳</summary>
|
||||
/// <param name="appInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Object?> PingLocal(AppInfo? appInfo)
|
||||
{
|
||||
var local = Factory?.Local;
|
||||
if (local == null || local.Info == null) return null;
|
||||
|
||||
return await local.PingAsync(appInfo);
|
||||
}
|
||||
|
||||
private TimeSpan _span;
|
||||
/// <summary>获取相对于服务器的当前时间,避免两端时间差</summary>
|
||||
/// <returns></returns>
|
||||
|
@ -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();
|
||||
|
|
|
@ -113,6 +113,15 @@ public class LocalStarClient
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>向StarAgent发送心跳</summary>
|
||||
/// <returns></returns>
|
||||
public async Task<PingResponse?> PingAsync(AppInfo? appInfo)
|
||||
{
|
||||
Init();
|
||||
|
||||
return await _client.InvokeAsync<PingResponse>("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";
|
||||
|
|
|
@ -271,6 +271,7 @@ public class StarFactory : DisposeBase
|
|||
|
||||
var client = new AppClient(Server)
|
||||
{
|
||||
Factory = this,
|
||||
AppId = AppId,
|
||||
AppName = AppName,
|
||||
ClientId = ClientId,
|
||||
|
|
Loading…
Reference in New Issue