public static IServiceHostClientBuilder UseConsulForDiscovery(this IServiceHostClientBuilder serviceHostBuilder, RegisterServer registerServer, params ServerAddress[] address) { serviceHostBuilder.RegisterService(cb => { cb.RegisterType <ConsulClientDiscovery>().As <IClientServiceDiscovery>().WithParameter("registerServer", registerServer).SingleInstance(); }); serviceHostBuilder.AddInitializer(container => { IClientServiceDiscovery clientDiscovery = container.Resolve <IClientServiceDiscovery>(); foreach (ServerAddress addr in address) { clientDiscovery.AddRoutesGetter(() => { ServerDesc serverDesc = new ServerDesc { ServerAddress = addr }; return(Task.FromResult(serverDesc)); }); } }); return(serviceHostBuilder); }
public QuartzHealthCheck(ILogger logger, IClientServiceDiscovery serviceDiscovery, int intervalMinute) { if (intervalMinute == 0 || intervalMinute > 60) { throw new ArgumentOutOfRangeException($"intervalMinite must between 1 and 60, current is {intervalMinute}"); } _cron = $"0 0/{intervalMinute} * * * ?"; _logger = logger; _serviceDiscovery = serviceDiscovery; }
public RemoteServiceCaller(IClientServiceDiscovery serviceDiscovery, IAddressSelector addressSelector, ITransportClientFactory transportClientFactory, ITypeConvertProvider typeConvertProvider, IServiceTokenGetter serviceTokenGetter, ILogger logger, int retryTimes = -1) { _serviceDiscovery = serviceDiscovery; _addressSelector = addressSelector; _transportClientFactory = transportClientFactory; _typeConvertProvider = typeConvertProvider; _serviceTokenGetter = serviceTokenGetter; _logger = logger; _retryTimes = retryTimes; }
public RemoteServiceCaller(IClientServiceDiscovery serviceDiscovery, IAddressSelector addressSelector, ClientSenderFactory clientSenderFactory, IServiceTokenGetter serviceTokenGetter, ILogger logger) { _serviceDiscovery = serviceDiscovery; _addressSelector = addressSelector; _clientSenderFactory = clientSenderFactory; _serviceTokenGetter = serviceTokenGetter; _logger = logger; _middlewares = new Stack <Func <ClientRequestDel, ClientRequestDel> >(); }
public RemoteServiceCaller(IClientServiceDiscovery serviceDiscovery, IAddressSelector addressSelector, ClientSenderFactory clientSenderFactory, IServiceTokenGetter serviceTokenGetter, IJimuDiagnostic jimuApm, ILoggerFactory loggerFactory) { _serviceDiscovery = serviceDiscovery; _addressSelector = addressSelector; _clientSenderFactory = clientSenderFactory; _serviceTokenGetter = serviceTokenGetter; _logger = loggerFactory.Create(this.GetType()); _middlewares = new Stack <Func <ClientRequestDel, ClientRequestDel> >(); _jimuApm = jimuApm; }
public RemoteServiceExecutor(IClientServiceDiscovery serviceDiscovery, IAddressSelector addressSelector, IServiceTokenGetter serviceTokenGetter, ITransportClientFactory transportClientFactory, ITypeConvertProvider typeConvertProvider, ILogger logger, ISerializer serializer, IAuthorizationHandler authorizationHandler = null, ICache <string, List <ServerAddress> > cache = null, int retryTimes = -1) { _serviceDiscovery = serviceDiscovery; _addressSelector = addressSelector; _transportClientFactory = transportClientFactory; _typeConvertProvider = typeConvertProvider; _serviceTokenGetter = serviceTokenGetter; _authorizationHandler = authorizationHandler; _cache = cache; _logger = logger; _retryTimes = retryTimes; _serializer = serializer; }
public RpcSwaggerDocumentFilter(IClientServiceDiscovery clientServiceDiscovery) { _clientServiceDiscovery = clientServiceDiscovery; }
public static IServiceHostClientBuilder UseInServerForDiscovery(this IServiceHostClientBuilder serviceHostBuilder, params ServerAddress[] address) { serviceHostBuilder.RegisterService(cb => { cb.RegisterType <ClientServiceDiscovery>().As <IClientServiceDiscovery>().SingleInstance(); }); serviceHostBuilder.AddInitializer(container => { IClientServiceDiscovery clientDiscovery = container.Resolve <IClientServiceDiscovery>(); IRemoteServiceExecutor remoteExecutor = container.Resolve <IRemoteServiceExecutor>(); ISerializer serializer = container.Resolve <ISerializer>(); ITypeConvertProvider typeConverter = container.Resolve <ITypeConvertProvider>(); ILogger logger = container.Resolve <ILogger>(); StringBuilder sb = new StringBuilder(); foreach (ServerAddress addr in address) { sb.AppendFormat(addr.Code + ","); clientDiscovery.AddRoutesGetter(async() => { RemoteCallBackData result = await remoteExecutor.InvokeAsync(new List <ServerAddress>() { addr }, "Lamp.ServiceDiscovery.InServer.GetRoutesDescAsync".ToLower(), null, null); if (result == null || result.HasError) { return(null); } List <ServiceRouteDesc> routesDesc = (List <ServiceRouteDesc>)typeConverter.Convert(result.Result, typeof(List <ServiceRouteDesc>)); ServerDesc server = new ServerDesc { ServerAddress = addr, ServiceDescriptor = new List <ServiceDesc>() }; server.ServerAddress.IsHealth = true; foreach (ServiceRouteDesc desc in routesDesc) { ServiceDesc item = (ServiceDesc)desc.ServiceDescriptor.Clone(); server.ServiceDescriptor.Add(item); } return(server); }); } if (sb.Length > 0) { logger.Info($"[config]用服务端发现服务 {sb.ToString()}"); } }); serviceHostBuilder.AddRunner(container => { ClientServiceDiscovery clientServiceDiscovery = (ClientServiceDiscovery)container.Resolve <IClientServiceDiscovery>(); clientServiceDiscovery?.RunInInit().Wait(); }); return(serviceHostBuilder); }
public static IServiceCollection UseRpcSwagger(this IServiceCollection services, RpcSwaggerOptions options, IClientServiceDiscovery clientServiceDiscovery) { services.AddSwaggerGen(c => { c.CustomSchemaIds(type => type.FullName); if (options.Version.Length == 0) { c.SwaggerDoc("all", new Info { Title = options.Title, Version = "all" }); } else { foreach (string v in options.Version) { c.SwaggerDoc(v, new Info { Title = options.Title, Version = v }); } } c.DocumentFilter <RpcSwaggerDocumentFilter>(clientServiceDiscovery); }); return(services); }