Exemplo n.º 1
0
 public void SetServiceListCallback(string serviceName, Action <List <InformationServiceSet> > callback)
 {
     lock (_watchedServices)
     {
         if (!_watchedServices.TryGetValue(serviceName, out var watcher))
         {
             watcher = new ServiceWatcher(serviceName, _client
                                          , new RandomRoutingStrategy <InformationServiceSet>(), _logger, useNearest: false);
             _watchedServices.Add(serviceName, watcher);
         }
         watcher.SetCallback(callback);
     }
 }
Exemplo n.º 2
0
 public WatcherState GetServiceCurrentState(string serviceName)
 {
     lock (_watchedServices)
     {
         if (!_watchedServices.TryGetValue(serviceName, out var watcher))
         {
             watcher = new ServiceWatcher(serviceName, _client
                                          , new RandomRoutingStrategy <InformationServiceSet>(), _logger, useNearest: false);
             _watchedServices.Add(serviceName, watcher);
         }
         return(watcher.State);
     }
 }
Exemplo n.º 3
0
 public Task <InformationService> GetServiceInstanceAsync(string serviceName)
 {
     lock (_watchedServices)
     {
         if (!_watchedServices.TryGetValue(serviceName, out ServiceWatcher watcher))
         {
             watcher = new ServiceWatcher(serviceName, _client
                                          , new RandomRoutingStrategy <InformationServiceSet>(), _logger);
             _watchedServices.Add(serviceName, watcher);
         }
         //We either have one or have made one now so lets carry on
         return(watcher.GetNextServiceInstanceAsync());
     }
 }
Exemplo n.º 4
0
 public Task <InformationService> GetNearestServiceInstanceAsync(string serviceName)
 {
     lock (_watchedServices)
     {
         if (!_watchedServices.TryGetValue(serviceName, out var watcher))
         {
             watcher = new ServiceWatcher(serviceName, _client, UseTopRouting <InformationServiceSet> .Default, _logger, useNearest: true);
             _watchedServices.Add(serviceName, watcher);
         }
         else
         {
             if (!watcher.IsNearest)
             {
                 watcher.IsNearest       = true;
                 watcher.RoutingStrategy = UseTopRouting <InformationServiceSet> .Default;
                 _logger.LogInformation("Changed service lookup type for service of {serviceName} from any random to nearest", serviceName);
             }
         }
         return(watcher.GetNextServiceInstanceAsync());
     }
 }
Exemplo n.º 5
0
 public Task <InformationService> GetServiceInstanceAsync(string serviceName)
 {
     lock (_watchedServices)
     {
         if (!_watchedServices.TryGetValue(serviceName, out var watcher))
         {
             watcher = new ServiceWatcher(serviceName, _client
                                          , RandomRoutingStrategy <InformationServiceSet> .Default, _logger, useNearest: false);
             _watchedServices.Add(serviceName, watcher);
         }
         else
         {
             if (watcher.IsNearest)
             {
                 watcher.IsNearest       = false;
                 watcher.RoutingStrategy = RandomRoutingStrategy <InformationServiceSet> .Default;
                 _logger?.LogInformation("Changed service lookup type for service of {serviceName} from nearest to any random", serviceName);
             }
         }
         //We either have one or have made one now so lets carry on
         return(watcher.GetNextServiceInstanceAsync());
     }
 }