diff --git a/ZeroLevel.Discovery/Controllers/RoutesController.cs b/ZeroLevel.Discovery/Controllers/RoutesController.cs index 779fa98..798ff2b 100644 --- a/ZeroLevel.Discovery/Controllers/RoutesController.cs +++ b/ZeroLevel.Discovery/Controllers/RoutesController.cs @@ -33,22 +33,5 @@ namespace ZeroLevel.Discovery return BadRequestAnswer(request, ex); } } - - [HttpPost] - [Route("api/v0/routes")] - [ResponseType(typeof(InvokeResult))] - public HttpResponseMessage AddRoute(HttpRequestMessage request, ExServiceInfo service) - { - try - { - var ir = Injector.Default.Resolve().Append(service); - return request.CreateSelfDestroyingResponse(ir); - } - catch (Exception ex) - { - Log.Error(ex, "Error with append endpoint"); - return BadRequestAnswer(request, ex); - } - } } } \ No newline at end of file diff --git a/ZeroLevel.Discovery/DiscoveryService.cs b/ZeroLevel.Discovery/DiscoveryService.cs index 40cafb6..a0ce469 100644 --- a/ZeroLevel.Discovery/DiscoveryService.cs +++ b/ZeroLevel.Discovery/DiscoveryService.cs @@ -39,7 +39,7 @@ namespace ZeroLevel.Discovery var socketPort = Configuration.Default.First("socketport"); _exInbox = ExchangeTransportFactory.GetServer(socketPort); _exInbox.RegisterInbox>("services", (_, __) => routeTable.Get()); - _exInbox.RegisterInbox("register", (info, _, __) => routeTable.Append(info)); + _exInbox.RegisterInbox("register", (info, _, client) => routeTable.Append(info, client)); Log.Info($"TCP server started {_exInbox.Endpoint.Address}:{socketPort}"); } diff --git a/ZeroLevel.Discovery/RouteTable.cs b/ZeroLevel.Discovery/RouteTable.cs index 7ac8637..8aea7f7 100644 --- a/ZeroLevel.Discovery/RouteTable.cs +++ b/ZeroLevel.Discovery/RouteTable.cs @@ -166,10 +166,11 @@ namespace ZeroLevel.Discovery Save(); } - public InvokeResult Append(ExServiceInfo serviceInfo) + public InvokeResult Append(ExServiceInfo serviceInfo, IZBackward client) { InvokeResult result = null; - if (Ping(serviceInfo.Endpoint, serviceInfo.ServiceKey)) + var endpoint = $"{client.Endpoint.Address}:{client.Endpoint.Port}"; + if (Ping(endpoint, serviceInfo.ServiceKey)) { var key = $"{serviceInfo.ServiceGroup}:{serviceInfo.ServiceType}:{serviceInfo.ServiceKey.Trim().ToLowerInvariant()}"; _lock.EnterWriteLock(); @@ -185,22 +186,22 @@ namespace ZeroLevel.Discovery ServiceType = serviceInfo.ServiceType, Endpoints = new List() }); - _table[key].Endpoints.Add(serviceInfo.Endpoint); - Log.Info($"The service '{serviceInfo.ServiceKey}' registered on endpoint: {serviceInfo.Endpoint}"); + _table[key].Endpoints.Add(endpoint); + Log.Info($"The service '{serviceInfo.ServiceKey}' registered on endpoint: {endpoint}"); } else { var exists = _table[key]; - if (exists.Endpoints.Contains(serviceInfo.Endpoint) == false) + if (exists.Endpoints.Contains(endpoint) == false) { - Log.Info($"The service '{serviceInfo.ServiceKey}' register endpoint: {serviceInfo.Endpoint}"); - exists.Endpoints.Add(serviceInfo.Endpoint); + Log.Info($"The service '{serviceInfo.ServiceKey}' register endpoint: {endpoint}"); + exists.Endpoints.Add(endpoint); } } } catch (Exception ex) { - Log.Error(ex, "Fault append service ({0} {1}) endpoint '{2}'", serviceInfo.ServiceKey, serviceInfo.Version, serviceInfo.Endpoint); + Log.Error(ex, "Fault append service ({0} {1}) endpoint '{2}'", serviceInfo.ServiceKey, serviceInfo.Version, endpoint); result = InvokeResult.Fault(ex.Message); } finally @@ -212,7 +213,7 @@ namespace ZeroLevel.Discovery } else { - result = InvokeResult.Fault($"Appending endpoint '{serviceInfo.Endpoint}' canceled for service {serviceInfo.ServiceKey} ({serviceInfo.Version}) because endpoind no avaliable"); + result = InvokeResult.Fault($"Appending endpoint '{endpoint}' canceled for service {serviceInfo.ServiceKey} ({serviceInfo.Version}) because endpoind no avaliable"); } return result; } diff --git a/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache b/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache index 6227be2..e6af631 100644 Binary files a/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache and b/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache differ diff --git a/ZeroLevel.UnitTests/ExchangeTests.cs b/ZeroLevel.UnitTests/ExchangeTests.cs index 0bd9044..3b9a861 100644 --- a/ZeroLevel.UnitTests/ExchangeTests.cs +++ b/ZeroLevel.UnitTests/ExchangeTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -18,7 +19,6 @@ namespace ZeroLevel.NetworkUnitTests // Arrange var info = new ExServiceInfo { - Endpoint = "192.168.1.11:7755", ServiceGroup = "MyServiceGroup", ServiceKey = "MyServiceKey", ServiceType = "MyServiceType", @@ -35,7 +35,7 @@ namespace ZeroLevel.NetworkUnitTests }); // Act - var client = ExchangeTransportFactory.GetClient(server.Endpoint.Address.ToString() + ":6666"); + var client = ExchangeTransportFactory.GetClient(IPAddress.Loopback.ToString() + ":6666"); var ir = client.Send("register", info); locker.WaitOne(1000); @@ -56,7 +56,6 @@ namespace ZeroLevel.NetworkUnitTests // Arrange var info1 = new ExServiceInfo { - Endpoint = "192.168.1.11:7755", ServiceGroup = "MyServiceGroup", ServiceKey = "MyServiceKey", ServiceType = "MyServiceType", @@ -64,7 +63,6 @@ namespace ZeroLevel.NetworkUnitTests }; var info2 = new ExServiceInfo { - Endpoint = "192.168.41.11:4564", ServiceGroup = "MyServiceGroup", ServiceKey = "MyServiceKey2", ServiceType = "MyServiceType", @@ -77,7 +75,7 @@ namespace ZeroLevel.NetworkUnitTests server.RegisterInbox>("services", (_, __) => new[] { info1, info2 }); // Act - var client = ExchangeTransportFactory.GetClient(server.Endpoint.Address.ToString() + ":6666"); + var client = ExchangeTransportFactory.GetClient(IPAddress.Loopback.ToString() + ":6666"); var ir = client.Request>("services", response => { received = response; diff --git a/ZeroLevel/Services/Network/Models/ExServiceInfo.cs b/ZeroLevel/Services/Network/Models/ExServiceInfo.cs index 2c3ca95..22e88a2 100644 --- a/ZeroLevel/Services/Network/Models/ExServiceInfo.cs +++ b/ZeroLevel/Services/Network/Models/ExServiceInfo.cs @@ -30,13 +30,6 @@ namespace ZeroLevel.Network /// [DataMember] public string ServiceType { get; set; } = DEFAULT_TYPE_NAME; - - /// - /// Connection point, address - /// - [DataMember] - public string Endpoint { get; set; } - /// /// Service version /// @@ -51,8 +44,6 @@ namespace ZeroLevel.Network if (string.Compare(this.ServiceKey, other.ServiceKey, true) != 0) return false; if (string.Compare(this.ServiceGroup, other.ServiceGroup, true) != 0) return false; if (string.Compare(this.ServiceType, other.ServiceType, true) != 0) return false; - - if (string.Compare(this.Endpoint, other.Endpoint, true) != 0) return false; if (string.Compare(this.Version, other.Version, true) != 0) return false; return true; } @@ -64,7 +55,7 @@ namespace ZeroLevel.Network public override int GetHashCode() { - return this.ServiceKey.GetHashCode() ^ this.Endpoint.GetHashCode(); + return this.ServiceKey.GetHashCode(); } public void Serialize(IBinaryWriter writer) @@ -72,7 +63,6 @@ namespace ZeroLevel.Network writer.WriteString(this.ServiceKey); writer.WriteString(this.ServiceGroup); writer.WriteString(this.ServiceType); - writer.WriteString(this.Endpoint); writer.WriteString(this.Version); } @@ -81,7 +71,6 @@ namespace ZeroLevel.Network this.ServiceKey = reader.ReadString(); this.ServiceGroup = reader.ReadString(); this.ServiceType = reader.ReadString(); - this.Endpoint = reader.ReadString(); this.Version = reader.ReadString(); } diff --git a/ZeroLevel/Services/Network/Services/ExServiceHost.cs b/ZeroLevel/Services/Network/Services/ExServiceHost.cs index 771d700..aae7de0 100644 --- a/ZeroLevel/Services/Network/Services/ExServiceHost.cs +++ b/ZeroLevel/Services/Network/Services/ExServiceHost.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Net; using System.Reflection; namespace ZeroLevel.Network @@ -46,7 +47,6 @@ namespace ZeroLevel.Network Server = server, ServiceInfo = new ExServiceInfo { - Endpoint = $"{server.Endpoint.Address}:{server.Endpoint.Port}", ServiceKey = service.Key, Version = service.Version, ServiceGroup = service.Group, @@ -88,7 +88,6 @@ namespace ZeroLevel.Network Server = server, ServiceInfo = new ExServiceInfo { - Endpoint = $"{server.Endpoint.Address}:{server.Endpoint.Port}", ServiceKey = serviceInfo.ServiceKey, Version = serviceInfo.Version, ServiceGroup = serviceInfo.ServiceGroup, diff --git a/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache b/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache index 431e5cf..1a69533 100644 --- a/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache +++ b/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -4d221d21073e6ec70fc75d0c6e7d2458aa0f2b9a +23b05e1da25edde99ed56a899f894605a2243d39