Example #1
0
 public async Task RegisterServiceAsync(string serviceName, string serviceId, string version, Uri uri)
 {
     _serviceName = serviceName;
     _serviceId = serviceId;
     _version = version;
     _uri = uri;
     var x = new ConsulRestClient();
     await x.RegisterServiceAsync(serviceName, serviceId, uri).ConfigureAwait(false);
     StartReaper();
 }
Example #2
0
        public async Task RegisterServiceAsync(string serviceName, string serviceId, string version, Uri uri)
        {
            _serviceName = serviceName;
            _serviceId   = serviceId;
            _version     = version;
            _uri         = uri;
            var x = new ConsulRestClient();
            await x.RegisterServiceAsync(serviceName, serviceId, uri).ConfigureAwait(false);

            StartReaper();
        }
Example #3
0
        public async Task<ServiceInformation[]> FindServiceInstancesAsync(string name)
        {
            if (_useEbayFabio)
            {
                return new[] { new ServiceInformation("http://localhost", 9999) };
            }

            var x = new ConsulRestClient();
            var res = await x.FindServiceAsync(name).ConfigureAwait(false);

            return res;
        }
Example #4
0
        public async Task <ServiceInformation[]> FindServiceInstancesAsync(string name)
        {
            if (_useEbayFabio)
            {
                return(new[] { new ServiceInformation("http://localhost", 9999) });
            }

            var x   = new ConsulRestClient();
            var res = await x.FindServiceAsync(name).ConfigureAwait(false);

            return(res);
        }
Example #5
0
        private void StartReaper()
        {
            Task.Factory.StartNew(async () =>
            {
                await Task.Delay(1000).ConfigureAwait(false);
                Logger.Information("Reaper: started..");
                var c = new ConsulRestClient();
                var lookup = new HashSet<string>();
                while (true)
                {
                    try
                    {
                        var res = await c.GetCriticalServicesAsync().ConfigureAwait(false);
                        foreach (var criticalServiceId in res)
                        {
                            if (lookup.Contains(criticalServiceId))
                            {
                                await c.DeregisterServiceAsync(criticalServiceId).ConfigureAwait(false);
                                Logger.Information("Reaper: Removing {ServiceId}", criticalServiceId);
                            }
                            else
                            {
                                lookup.Add(criticalServiceId);
                                Logger.Information("Reaper: Marking {ServiceId}", criticalServiceId);
                            }
                        }
                        //remove entries that are no longer critical
                        lookup.RemoveWhere(i => !res.Contains(i));
                    }
                    catch (Exception x)
                    {
                        Logger.Error(x, "Crashed");
                    }

                    await Task.Delay(5000).ConfigureAwait(false);
                }
            });
        }
Example #6
0
        private void StartReaper()
        {
            Task.Factory.StartNew(async() =>
            {
                await Task.Delay(1000).ConfigureAwait(false);
                Logger.Information("Reaper: started..");
                var c      = new ConsulRestClient();
                var lookup = new HashSet <string>();
                while (true)
                {
                    try
                    {
                        var res = await c.GetCriticalServicesAsync().ConfigureAwait(false);
                        foreach (var criticalServiceId in res)
                        {
                            if (lookup.Contains(criticalServiceId))
                            {
                                await c.DeregisterServiceAsync(criticalServiceId).ConfigureAwait(false);
                                Logger.Information("Reaper: Removing {ServiceId}", criticalServiceId);
                            }
                            else
                            {
                                lookup.Add(criticalServiceId);
                                Logger.Information("Reaper: Marking {ServiceId}", criticalServiceId);
                            }
                        }
                        //remove entries that are no longer critical
                        lookup.RemoveWhere(i => !res.Contains(i));
                    }
                    catch (Exception x)
                    {
                        Logger.Error(x, "Crashed");
                    }

                    await Task.Delay(5000).ConfigureAwait(false);
                }
            });
        }
Example #7
0
        public async Task <T> KVGetAsync <T>(string key)
        {
            var x = new ConsulRestClient();

            return(await x.KVGetAsync <T>(key).ConfigureAwait(false));;
        }
Example #8
0
 public async Task KVPutAsync(string key, object value)
 {
     var x = new ConsulRestClient();
     await x.KVPutAsync(key, value).ConfigureAwait(false);
 }