public static void Init(ThriftClientConfig thriftClientConfig, string formAppName = "App") { if (config != null) { return; } if (thriftClientConfig == null) { throw new ArgumentNullException(nameof(thriftClientConfig), "thriftClientConfig is null"); } if (string.IsNullOrWhiteSpace(thriftClientConfig.Name) || thriftClientConfig.Port == 0) { throw new ArgumentNullException("thriftClientConfig.Name is null or thriftClientConfig.Port is null"); } if (thriftClientConfig.Consul == null && string.IsNullOrWhiteSpace(thriftClientConfig.IPHost)) { throw new ArgumentNullException("Consul is null && IPHost is null"); } config = thriftClientConfig; visitAppName = formAppName; }
private static void LoadConf() { if (config != null) { return; } string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFileName); if (!File.Exists(filePath)) { filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", configFileName); if (!File.Exists(filePath)) { throw new ArgumentNullException($"fild nofound path:{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFileName)} path:{filePath}"); } } config = ThriftConfig.GetConfig(filePath); if (config == null) { throw new ArgumentNullException($"config is null path:{filePath}"); } visitAppName = ConfigurationManager.AppSettings.Get("AppName") ?? visitAppName; SetFreeEvent(); }
public T CreateScribeClient <T>( ThriftClientManager manager, ScopedServer server, TProtocolFactory protocolFactory) where T : class { ThriftClientConfig config = new ThriftClientConfig(); config.ConnectTimeout = TimeSpan.FromSeconds(600); config.ReceiveTimeout = TimeSpan.FromSeconds(600); config.ReadTimeout = TimeSpan.FromSeconds(600); config.WriteTimeout = TimeSpan.FromSeconds(600); var thriftClient = new ThriftClient(manager, typeof(T), config, typeof(T).Name); return(thriftClient.OpenAsync( new FramedClientConnector("localhost", server.Port, protocolFactory)) .GetAwaiter().GetResult() as T); }
private static bool InvaildConfig(ThriftClientConfig config) { return(config == null || config.Port == 0 || (config.Consul == null && config.IPHost == null)); }
public static IServiceCollection Add$serviceclassname$Thrift(this IServiceCollection services, ThriftClientConfig config) { $dllname$.ThriftClient.Init(config); services.AddSingleton <IThriftClient, ThriftClient>(); services.AddTransient(_ => _.GetRequiredService <IThriftClient>().ClientOne); return(services); }