|
|
|
@ -516,26 +516,29 @@ namespace ZeroLevel.Network
|
|
|
|
|
if (discovery_endpoint.Success)
|
|
|
|
|
{
|
|
|
|
|
var discoveryClient = _cachee.GetClient(discovery_endpoint.Value, true);
|
|
|
|
|
var services = _cachee.ServerList.
|
|
|
|
|
Select(s =>
|
|
|
|
|
{
|
|
|
|
|
var info = MessageSerializer.Copy(_owner.ServiceInfo);
|
|
|
|
|
info.Port = s.LocalEndpoint.Port;
|
|
|
|
|
return info;
|
|
|
|
|
}).
|
|
|
|
|
ToList();
|
|
|
|
|
foreach (var service in services)
|
|
|
|
|
{
|
|
|
|
|
var request = discoveryClient.Request<ZeroServiceInfo, InvokeResult>("register", service, r =>
|
|
|
|
|
if (discoveryClient != null)
|
|
|
|
|
{
|
|
|
|
|
var services = _cachee.ServerList.
|
|
|
|
|
Select(s =>
|
|
|
|
|
{
|
|
|
|
|
var info = MessageSerializer.Copy(_owner.ServiceInfo);
|
|
|
|
|
info.Port = s.LocalEndpoint.Port;
|
|
|
|
|
return info;
|
|
|
|
|
}).
|
|
|
|
|
ToList();
|
|
|
|
|
foreach (var service in services)
|
|
|
|
|
{
|
|
|
|
|
if (!r.Success)
|
|
|
|
|
var request = discoveryClient.Request<ZeroServiceInfo, InvokeResult>("register", service, r =>
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.RegisterServicesInDiscovery] Register canceled. {r.Comment}");
|
|
|
|
|
if (!r.Success)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.RegisterServicesInDiscovery] Register canceled. {r.Comment}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (request.Success == false)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.RegisterServicesInDiscovery] Register canceled.{request.Comment}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (request.Success == false)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.RegisterServicesInDiscovery] Register canceled.{request.Comment}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -547,55 +550,58 @@ namespace ZeroLevel.Network
|
|
|
|
|
if (discovery_endpoint.Success)
|
|
|
|
|
{
|
|
|
|
|
var discoveryClient = _cachee.GetClient(discovery_endpoint.Value, true);
|
|
|
|
|
try
|
|
|
|
|
if (discoveryClient != null)
|
|
|
|
|
{
|
|
|
|
|
var ir = discoveryClient.Request<IEnumerable<ServiceEndpointsInfo>>("services", records =>
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (records == null)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning("[Exchange.UpdateServiceListFromDiscovery] UpdateServiceListInfo. Discrovery response is empty");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var endpoints = new HashSet<IPEndPoint>();
|
|
|
|
|
_dicovery_aliases.BeginUpdate();
|
|
|
|
|
try
|
|
|
|
|
var ir = discoveryClient.Request<IEnumerable<ServiceEndpointsInfo>>("services", records =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var service in records)
|
|
|
|
|
if (records == null)
|
|
|
|
|
{
|
|
|
|
|
endpoints.Clear();
|
|
|
|
|
foreach (var ep in service.Endpoints)
|
|
|
|
|
Log.SystemWarning("[Exchange.UpdateServiceListFromDiscovery] UpdateServiceListInfo. Discrovery response is empty");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var endpoints = new HashSet<IPEndPoint>();
|
|
|
|
|
_dicovery_aliases.BeginUpdate();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var service in records)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var endpoint = NetUtils.CreateIPEndPoint(ep);
|
|
|
|
|
endpoints.Add(endpoint);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
endpoints.Clear();
|
|
|
|
|
foreach (var ep in service.Endpoints)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.UpdateServiceListFromDiscovery] Can't parse address {ep} as IPEndPoint");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var endpoint = NetUtils.CreateIPEndPoint(ep);
|
|
|
|
|
endpoints.Add(endpoint);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.UpdateServiceListFromDiscovery] Can't parse address {ep} as IPEndPoint");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_dicovery_aliases.Set(service.ServiceKey,
|
|
|
|
|
service.ServiceType,
|
|
|
|
|
service.ServiceGroup,
|
|
|
|
|
endpoints);
|
|
|
|
|
}
|
|
|
|
|
_dicovery_aliases.Set(service.ServiceKey,
|
|
|
|
|
service.ServiceType,
|
|
|
|
|
service.ServiceGroup,
|
|
|
|
|
endpoints);
|
|
|
|
|
_dicovery_aliases.Commit();
|
|
|
|
|
}
|
|
|
|
|
_dicovery_aliases.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_dicovery_aliases.Rollback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (!ir.Success)
|
|
|
|
|
{
|
|
|
|
|
_dicovery_aliases.Rollback();
|
|
|
|
|
Log.SystemWarning($"[Exchange.UpdateServiceListFromDiscovery] Error request to inbox 'services'. {ir.Comment}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (!ir.Success)
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemWarning($"[Exchange.UpdateServiceListFromDiscovery] Error request to inbox 'services'. {ir.Comment}");
|
|
|
|
|
Log.SystemError(ex, "[Exchange.UpdateServiceListFromDiscovery] Discovery service response is absent");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemError(ex, "[Exchange.UpdateServiceListFromDiscovery] Discovery service response is absent");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
@ -777,6 +783,7 @@ namespace ZeroLevel.Network
|
|
|
|
|
Log.SystemError(ex, $"[Exchange.GetClientEnumerator] Can't get transport for endpoint '{endpoint}'");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (transport == null) continue;
|
|
|
|
|
yield return transport;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -812,6 +819,7 @@ namespace ZeroLevel.Network
|
|
|
|
|
Log.SystemError(ex, $"[Exchange.GetClientEnumeratorByType] Can't get transport for endpoint '{endpoint}'");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (transport == null) continue;
|
|
|
|
|
yield return transport;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -847,6 +855,7 @@ namespace ZeroLevel.Network
|
|
|
|
|
Log.SystemError(ex, $"[Exchange.GetClientEnumeratorByGroup] Can't get transport for endpoint '{service}'");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (transport == null) continue;
|
|
|
|
|
yield return transport;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -891,6 +900,7 @@ namespace ZeroLevel.Network
|
|
|
|
|
Log.SystemError(ex, $"[Exchange.CallService] Can't get transport for service '{serviceKey}'");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (transport == null) continue;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
success = callHandler(transport);
|
|
|
|
|