private ConnectionManager(IListener listener, IServiceDiscovery serviceDiscovery, TimeSpan? serviceDiscoveryPeriod)
        {
            this.remoteServices = new Dictionary<ServiceUri, PerformanceStatistics>();
            this.Listener = listener;
            if (serviceDiscovery != null)
            {
                this.serviceDiscovery = serviceDiscovery;
                this.serviceDiscoveryPeriod = serviceDiscoveryPeriod ?? new TimeSpan(hours: 0, minutes: 0, seconds: 5);
                this.serviceDiscoveryThread = new Thread(() =>
                {
                    while (!this.shouldStop)
                    {
                        var availableServices = this.serviceDiscovery.GetPerformanceStatistics();
                        lock (this.remoteServicesLock)
                        {
                            this.remoteServices.Clear();
                            foreach (var service in availableServices.Keys)
                            {
                                if (this.Listener==null || !service.Equals(this.Listener.CallbackUri))
                                {
                                    this.remoteServices.Add(service, availableServices[service]);
                                }
                            }
                        }

                        Thread.Sleep(this.serviceDiscoveryPeriod);
                    }
                });

                this.serviceDiscoveryThread.Start();
            }
        }
        public ConsulServiceGatewayFactory(DefaultGatewayDelegate defaultGateway, IServiceDiscovery<ConsulService, ServiceRegistration> discoveryClient)
        {
            defaultGateway.ThrowIfNull(nameof(defaultGateway));
            discoveryClient.ThrowIfNull(nameof(discoveryClient));

            this.defaultGateway = defaultGateway;
            this.discoveryClient = discoveryClient;
            this.LocalTypes = HostContext.Metadata?.RequestTypes ?? new HashSet<Type>();
        }
 public ConnectionManager(
     KeyValuePair<ServiceUri,PerformanceStatistics>? remoteService,
     IListener listener,
     IServiceDiscovery serviceDiscovery = null,
     TimeSpan? serviceDiscoveryPeriod = null)
     : this(remoteService.HasValue ? new Dictionary<ServiceUri, PerformanceStatistics>() { {remoteService.Value.Key, remoteService.Value.Value} } : null,
         listener,
         serviceDiscovery,
         serviceDiscoveryPeriod)
 {
 }
        private void RegisterService(IAppHost host)
        {
            ServiceDiscovery = Settings.GetDiscoveryClient() ?? new ConsulDiscovery();
            ServiceDiscovery.Register(host);

            // register servicestack discovery services
            host.Register(ServiceDiscovery);
            host.GetContainer()
                .Register<IServiceGatewayFactory>(x => new ConsulServiceGatewayFactory(Settings.GetGateway(), ServiceDiscovery))
                .ReusedWithin(ReuseScope.None);
        }
 public ConnectionManager(
     IDictionary<ServiceUri, PerformanceStatistics> remoteServices,
     IListener listener,
     IServiceDiscovery serviceDiscovery = null,
     TimeSpan? serviceDiscoveryPeriod = null)
     : this(listener, serviceDiscovery, serviceDiscoveryPeriod)
 {
     if (remoteServices != null)
     {
         lock (this.remoteServicesLock)
         {
             foreach (var remoteService in remoteServices.Keys)
             {
                 if(!this.remoteServices.ContainsKey(remoteService))
                 {
                     this.remoteServices.Add(remoteService, remoteServices[remoteService]);
                 }
             }
         }
     }
 }
Exemple #6
0
 public DdGrpcClientFactory(string name, IServiceDiscovery serviceDiscovery, AuthInterceptor authInterceptor)
 {
     _name             = name;
     _serviceDiscovery = serviceDiscovery;
     _authInterceptor  = authInterceptor;
 }
Exemple #7
0
        public static async Task <ServiceRestApiClient> Create(string serviceName, IServiceDiscovery discovery)
        {
            var client = new ServiceRestApiClient(serviceName, discovery);

            return(await client.Init() ? client : null);
        }
 public MicroserviceBusiness(IServiceDiscovery serviceDiscovery, IConfig config, IDbRepository <ApiGatewayConfigurationInfo> apigatewayRepository)
 {
     _serviceDiscovery     = serviceDiscovery;
     _config               = config;
     _apigatewayRepository = apigatewayRepository;
 }
 public SettingsController(IServiceDiscovery serviceDiscovery, SampleSettings sampleSettings)
 {
     this.serviceDiscovery = serviceDiscovery;
     this.sampleSettings   = sampleSettings;
 }
Exemple #10
0
 public FallbackFactoryFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, TFallbackFactory fallbackFactory) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory, GetFallback(fallbackFactory))
 {
     FallbackFactory = fallbackFactory;
 }
Exemple #11
0
 public ServicePool(IServiceDiscovery serviceDiscovery, IServiceSelector serviceSelector, ServicePoolOptions options)
 {
     _serviceDiscovery = serviceDiscovery;
     _serviceSelector  = serviceSelector;
     _options          = options;
 }
Exemple #12
0
 public ServiceManager(ILogger log, IServiceDiscovery discovery)
 {
     _log       = log;
     _discovery = discovery;
 }
Exemple #13
0
        public static async Task <IList <IServiceInstance> > GetServiceInstancesWithCacheAsync(this IServiceDiscovery serviceDiscovery, string serviceId, IDistributedCache distributedCache, string serviceInstancesKeyPrefix = "ServiceDiscovery-ServiceInstances-")
        {
            // if distributed cache was provided, just make the call back to the provider
            if (distributedCache != null)
            {
                // check the cache for existing service instances
                var instanceData = await distributedCache.GetAsync(serviceInstancesKeyPrefix + serviceId);

                if (instanceData != null && instanceData.Length > 0)
                {
                    return(DeserializeFromCache <List <SerializableIServiceInstance> >(instanceData).ToList <IServiceInstance>());
                }
            }

            // cache not found or instances not found, call out to the provider
            var instances = serviceDiscovery.GetServiceInstances(serviceId);

            if (distributedCache != null)
            {
                await distributedCache.SetAsync(serviceInstancesKeyPrefix + serviceId, SerializeForCache(MapToSerializable(instances)));
            }

            return(instances);
        }
Exemple #14
0
 public ValuesController(SampleService sampleService, IServiceDiscovery consul)
 {
     this._sampleService = sampleService;
     this._consul = consul;
 }
Exemple #15
0
 public FallbackFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, object fallback) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory)
 {
     _fallback = fallback;
 }
Exemple #16
0
 /// <summary>
 /// Override the default discovery consul client
 /// </summary>
 /// <param name="discoveryClient">the IDiscovery client</param>
 public void AddServiceDiscovery(IServiceDiscovery <ConsulService, ServiceRegistration> discoveryClient)
 {
     this.discoveryClient = discoveryClient;
 }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="sqlSugarDbContextFactory"></param>
 /// <param name="serviceDiscovery"></param>
 /// <param name="cachingProviderFactory"></param>
 public MicroserviceController(ISqlSugarDbContextFactory sqlSugarDbContextFactory, IServiceDiscovery serviceDiscovery, ICachingProviderFactory cachingProviderFactory)
 {
     _sqlSugarDbContextFactory = sqlSugarDbContextFactory;
     _serviceDiscovery         = serviceDiscovery;
     _cachingProviderFactory   = cachingProviderFactory;
     _adminDbContext           = _sqlSugarDbContextFactory.Get("admin");
 }
Exemple #18
0
 public DefaultDynamicMiddleUrl(IServiceDiscovery serviceDiscovery)
 {
     this.serviceDiscovery = serviceDiscovery;
 }
Exemple #19
0
 public static IFeignBuilder AddServiceDiscovery(this IFeignBuilder feignBuilder, IServiceDiscovery serviceDiscovery)
 {
     feignBuilder.Services.TryAddSingleton(serviceDiscovery);
     return(feignBuilder);
 }
Exemple #20
0
 public RegisterController(IServiceDiscovery serviceDiscovery, IServicePersistance servicePersistance)
 {
     _serviceDiscovery   = serviceDiscovery;
     _servicePersistance = servicePersistance;
 }
 public ServiceDiscoveryStartup(IServiceDiscovery serviceDiscovery, UraganoSettings uraganoSettings)
 {
     ServiceDiscovery = serviceDiscovery;
     ServerSettings   = uraganoSettings.ServerSettings;
 }
Exemple #22
0
 public DkmsGateway(IDkmsRouter dkmsRouter, IServiceDiscovery serviceDiscovery, IMessageTransferProxy messageTransferProxy)
 {
     _dkmsRouter           = dkmsRouter;
     _serviceDiscovery     = serviceDiscovery;
     _messageTransferProxy = messageTransferProxy;
 }
 public FallbackFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, TFallback fallback) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory, fallback)
 {
     Fallback = fallback;
     _serviceTypeFeignClientPipeline = _globalFeignClientPipeline?.GetServicePipeline <TService>();
 }
 public MicroserviceBusiness(IServiceDiscovery serviceDiscovery)
 {
     _serviceDiscovery = serviceDiscovery;
 }
Exemple #25
0
 //Sync API
 public static ServiceInformation[] GetServiceInstances(this IServiceDiscovery self, string serviceName)
 {
     return(self.GetServiceInstancesAsync(serviceName).Result);
 }
Exemple #26
0
 public LoadBalancerFactory(IServiceDiscovery serviceProvider)
 {
     _serviceProvider = serviceProvider;
 }
Exemple #27
0
 public static Uri ResolveUri(this IServiceDiscovery self, string serviceName, string relativeUri, string scheme = "http")
 {
     return(self.ResolveUriAsync(serviceName, relativeUri, scheme).Result);
 }
Exemple #28
0
        public RpcServer(ServerAddress address, IServiceEntryContainer serviceEntryContainer, ISerializer serializer, ILogger logger, IServiceDiscovery serviceDiscovery)
        {
            _address               = address;
            _serializer            = serializer;
            _logger                = logger;
            _serviceEntryContainer = serviceEntryContainer;

            _serviceDiscovery = serviceDiscovery;
            //中间件执行委托
            _middlewares = new Stack <Func <RequestDel, RequestDel> >();
        }
Exemple #29
0
 //Single instance
 public static Task <Uri> ResolveUriAsync(this IServiceDiscovery self, string serviceName, string relativeUri, string scheme = "http")
 {
     return(self.ResolveUriAsync(serviceName, new Uri(relativeUri, UriKind.Relative), scheme));
 }
        public static IServiceHostServerBuilder UseJwtForOAuth(this IServiceHostServerBuilder serviceHostBuilder, JwtAuthorizationOptions options)
        {
            serviceHostBuilder.AddRunner(container =>
            {
                ILogger logger = container.Resolve <ILogger>();
                logger.Info($"[config]use jwt for OAuth");

                while (!container.IsRegistered <IServer>() || !container.IsRegistered <IServiceDiscovery>())
                {
                    Thread.Sleep(200);
                }
                IServer server         = container.Resolve <IServer>();
                ISerializer serializer = container.Resolve <ISerializer>();
                server.UseMiddleware <JwtAuthorizationMiddleware>(options, serializer);

                if (string.IsNullOrEmpty(options.TokenEndpointPath))
                {
                    return;
                }

                if (options.ServerIp == "localhost" || options.ServerIp == "127.0.0.1")
                {
                    IServiceDiscovery discovery = container.Resolve <IServiceDiscovery>();
                    ServerAddress addr          = new ServerAddress(options.ServerIp, options.ServerPort);

                    List <ServiceRoute> tokenRoute = new List <ServiceRoute> {
                        new ServiceRoute
                        {
                            Address = new List <ServerAddress> {
                                addr
                            },
                            ServiceDescriptor = new ServiceDesc
                            {
                                Id         = options.TokenEndpointPath.TrimStart('/'),
                                RoutePath  = options.TokenEndpointPath,
                                HttpMethod = "Post",
                                Parameters = serializer.Serialize <string>(new List <ServiceParameterDesc> {
                                    new ServiceParameterDesc
                                    {
                                        Comment = "username",
                                        Format  = "System.String",
                                        Name    = "username",
                                        Type    = "object"
                                    },
                                    new ServiceParameterDesc
                                    {
                                        Comment = "password",
                                        Format  = "System.String",
                                        Name    = "password",
                                        Type    = "object"
                                    },
                                }),
                                ReturnDesc = serializer.Serialize <string>(new ServiceReturnDesc {
                                    Comment      = "Token",
                                    ReturnType   = "object",
                                    ReturnFormat = "{\"access_token\":\"System.String | token\", \"expired_in\":\"System.Int32 | expired timestamp which is the number of seconds between 1970-01-01 and expired datetime\"}"
                                })
                            }
                        }
                    };
                    discovery.ClearServiceAsync(tokenRoute.First().ServiceDescriptor.Id).Wait();
                    //discovery.SetRoutesAsync(tokenRoute);
                    discovery.AddRouteAsync(tokenRoute).Wait();
                }
            });
            return(serviceHostBuilder);
        }
 public SettingsController(IServiceDiscovery serviceDiscovery, LoggingSettings loggingSettings, SampleSettings sampleSettings)
 {
     this.serviceDiscovery = serviceDiscovery;
     this.loggingSettings  = loggingSettings;
     this.sampleSettings   = sampleSettings;
 }
Exemple #32
0
 private ServiceRestApiClient(string serviceName, IServiceDiscovery discovery) : base("")
 {
     _serviceName = serviceName;
     _discovery   = discovery;
 }
Exemple #33
0
        public RemoteExecutorContext(TransportMsg transportMessage, IServiceEntryContainer serviceEntryContainer,
                                     IResponse response, ISerializer serializer, ILogger logger, IServiceDiscovery serviceDiscovery)
        {
            Response         = response;
            TransportMessage = transportMessage;
            try
            {
                RemoteInvokeMessage = transportMessage.GetContent <RemoteCallData>(serializer);
            }
            catch (Exception ex)
            {
                logger.Error("failed to convert transportmsg.content to  RemoteCallerData.", ex);
                return;
            }

            ServiceEntry = serviceEntryContainer.GetServiceEntry()
                           .FirstOrDefault(x => x.Descriptor.Id == RemoteInvokeMessage.ServiceId);
            ServiceDesc serviceDesc;

            if (ServiceEntry == null)
            {
                logger.Warn($"not found service: {RemoteInvokeMessage.ServiceId}");
                List <ServiceRoute> router = serviceDiscovery.GetRoutesAsync().Result;
                serviceDesc = router.FirstOrDefault(o => o.ServiceDescriptor.Id == RemoteInvokeMessage.ServiceId).ServiceDescriptor;
            }
            else
            {
                serviceDesc = ServiceEntry.Descriptor;
            }

            RemoteInvokeMessage.Parameters = CheckParameters(RemoteInvokeMessage.Parameters, serviceDesc, serializer);
        }
        public static async Task <IList <IServiceInstance> > GetServiceInstancesWithCacheAsync(this IServiceDiscovery serviceDiscovery, string serviceId, IServiceCacheProvider serviceCacheProvider, string serviceInstancesKeyPrefix = "ServiceDiscovery-ServiceInstances-")
        {
            // if distributed cache was provided, just make the call back to the provider
            if (serviceCacheProvider != null)
            {
                // check the cache for existing service instances
                var services = await serviceCacheProvider.GetAsync(serviceInstancesKeyPrefix + serviceId);

                if (services != null && services.Count > 0)
                {
                    return(services);
                }
            }

            // cache not found or instances not found, call out to the provider
            var instances = serviceDiscovery.GetServiceInstances(serviceId) ?? new List <IServiceInstance>();

            if (serviceCacheProvider != null)
            {
                await serviceCacheProvider.SetAsync(serviceInstancesKeyPrefix + serviceId, instances, TimeSpan.FromMinutes(10));
            }

            return(instances);
        }
 public DefaultDynamicMiddleUrl(IServiceDiscovery serviceDiscovery, ILoadBalance loadBalance)
 {
     _serviceDiscovery = serviceDiscovery;
     _loadBalance      = loadBalance;
 }
        public static async Task <IList <IServiceInstance> > GetServiceInstancesWithCacheAsync(this IServiceDiscovery serviceDiscovery, string serviceId, ICacheProvider cacheProvider, TimeSpan time, string serviceInstancesKeyPrefix = "ServiceDiscovery-ServiceInstances-")
        {
            // if distributed cache was provided, just make the call back to the provider
            if (cacheProvider != null)
            {
                // check the cache for existing service instances
                var services = await cacheProvider.GetAsync <List <SerializableServiceInstance> >(serviceInstancesKeyPrefix + serviceId);

                if (services != null && services.Count > 0)
                {
                    return(services.ToList <IServiceInstance>());
                }
            }

            // cache not found or instances not found, call out to the provider
            var instances = serviceDiscovery.GetServiceInstances(serviceId) ?? new List <IServiceInstance>();

            if (cacheProvider != null)
            {
                List <SerializableServiceInstance> cacheValue = instances.Select(i => new SerializableServiceInstance(i)).ToList();
                await cacheProvider.SetAsync(serviceInstancesKeyPrefix + serviceId, cacheValue, time);
            }

            return(instances);
        }
Exemple #37
0
 public ServicesController(IServiceDiscovery consul)
 {
     this._consul = consul;
 }