/// <summary> /// Initializes a new instance of the <see cref="ConsulServiceRegistrar"/> class. /// </summary> /// <param name="registry">the Consul service registry to use when doing registrations</param> /// <param name="optionsMonitor">configuration options to use</param> /// <param name="registration">the registration to register with Consul</param> /// <param name="logger">optional logger</param> public NacosServiceRegistrar(INacosServiceRegistry registry, IOptionsMonitor <NacosDiscoveryOptions> optionsMonitor, INacosRegistration registration, ILogger <NacosServiceRegistrar> logger = null) { _registry = registry ?? throw new ArgumentNullException(nameof(registry)); _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); Registration = registration ?? throw new ArgumentNullException(nameof(registration)); _logger = logger; }
/// <inheritdoc/> public async Task <object> GetStatusAsync(INacosRegistration registration) { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } var request = new ListInstancesRequest() { ServiceName = registration.ServiceId, Clusters = registration.ClusterName }; var result = await _nacosClient.ListInstancesAsync(request); //ListInstancesResult result = Task.Run(async () => //{ // return //}).Result; foreach (Host check in result.Hosts) { if (check.Ip.Equals(registration.Host)) { if (check.Healthy == false) { return(OUT_OF_SERVICE); } } } return(UP); }
public S GetStatus <S>(INacosRegistration registration) where S : class { var result = Task.Run(async() => { return(await GetStatusAsync(registration)); }).Result; return((S)result); }
public ThisServiceInstance(INacosRegistration registration) { ServiceId = registration.ServiceId; Host = registration.Host; IsSecure = registration.IsSecure; Port = registration.Port; Metadata = registration.Metadata; Uri = registration.Uri; }
public Task DeregisterAsync(INacosRegistration registration) { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } return(DeregisterAsyncInternal(registration)); }
public void Deregister(INacosRegistration registration) { RemoveInstanceRequest request = new RemoveInstanceRequest() { Ip = registration.Host, Port = registration.Port, ServiceName = registration.ServiceId }; _nacosClient.RemoveInstanceAsync(request); }
public void SetStatus(INacosRegistration registration, string status) { ModifyInstanceHealthStatusRequest request = new ModifyInstanceHealthStatusRequest() { Ip = registration.Host, Port = registration.Port, ServiceName = registration.ServiceId, Healthy = registration.Healthy, NamespaceId = registration.Namespace }; _nacosClient.ModifyInstanceHealthStatusAsync(request); }
public void Register(INacosRegistration registration) { RegisterInstanceRequest request = new RegisterInstanceRequest() { ClusterName = registration.ClusterName, Ephemeral = registration.Ephemeral, ServiceName = registration.ServiceId, Enable = registration.Enable, GroupName = registration.GroupName, Ip = registration.Host, Port = registration.Port, NamespaceId = registration.Namespace }; _nacosClient.RegisterInstanceAsync(request); }
private async Task <bool> ResistryAsync(INacosRegistration registration) { RegisterInstanceRequest request = new RegisterInstanceRequest() { ClusterName = registration.ClusterName, Ephemeral = registration.Ephemeral, ServiceName = registration.ServiceId, Enable = registration.Enable, GroupName = registration.GroupName, Ip = registration.Host, Port = registration.Port, NamespaceId = registration.Namespace }; return(await _nacosClient.RegisterInstanceAsync(request)); }
private async Task DeregisterAsyncInternal(INacosRegistration registration) { if (Options.IsHeartBeatEnabled && _scheduler != null) { _scheduler.Remove(registration.ServiceId); } _logger?.LogInformation("Deregistering service with consul {instanceId} ", registration.ServiceId); ModifyInstanceHealthStatusRequest request = new ModifyInstanceHealthStatusRequest() { Ip = registration.Host, Port = registration.Port, ServiceName = registration.ServiceId, Healthy = registration.Healthy, NamespaceId = registration.Namespace }; await _nacosClient.ModifyInstanceHealthStatusAsync(request); }
private async Task RegisterAsyncInternal(INacosRegistration registration) { _logger?.LogInformation("Registering service with nacos {serviceId} ", registration.ServiceId); try { await ResistryAsync(registration).ConfigureAwait(false); if (Options.IsHeartBeatEnabled && _scheduler != null) { _scheduler.Add(registration.ServiceId); } } catch (Exception e) { if (Options.FailFast) { _logger?.LogError(e, "Error registering service with consul {serviceId} ", registration.ServiceId); throw; } _logger?.LogWarning(e, "Failfast is false. Error registering service with consul {serviceId} ", registration.ServiceId); } }
public void SetStatus(INacosRegistration registration, string status) { DeregisterAsync(registration).GetAwaiter().GetResult(); }
public void Register(INacosRegistration registration) { RegisterAsync(registration).GetAwaiter().GetResult(); }