protected virtual void FillServerConfig(ServerConfig config)
        {
            ThriftServerConfig thriftConfig = config as ThriftServerConfig;

            if (thriftConfig != null)
            {
                thriftConfig.WaitConsulTime        = thriftConfig.WaitConsulTime ?? TimeSpan.FromSeconds(3);
                thriftConfig.ServiceCheck          = thriftConfig.ServiceCheck ?? new ServiceCheckConfig();
                thriftConfig.ServiceCheck.Address  = GetLocalHost();
                thriftConfig.ServiceCheck.Interval = thriftConfig.ServiceCheck.Interval ?? TimeSpan.FromSeconds(10);
                thriftConfig.ServiceCheck.Timeout  = thriftConfig.ServiceCheck.Timeout ?? TimeSpan.FromSeconds(3);
                thriftConfig.ServiceCheck.Type     = thriftConfig.ServiceCheck.Type ?? "tcp";
            }
        }
示例#2
0
        protected virtual void Init()
        {
            ThriftServiceConfiguration configuration = new ThriftServiceConfiguration();
            ServiceConfig      serviceConfig         = configuration.GetServiceConfig();
            ThriftClientConfig clientConfig          = serviceConfig.Client as ThriftClientConfig;
            ThriftServerConfig serverConfig          = serviceConfig.Server as ThriftServerConfig;

            if (clientConfig == null)
            {
                throw new Exception("ClientConfig必须为ThriftClientConfig类型");
            }
            if (serverConfig == null)
            {
                throw new Exception("ServerConfig必须为ThriftServerConfig类型");
            }
            ThriftServiceRegistry serviceRegistry = new ThriftServiceRegistry(serviceConfig.RegistrationCenter, serverConfig.WaitConsulTime.Value);

            _cache.Add(typeof(IServiceConfiguration), configuration);
            _cache.Add(typeof(IServiceRegistry), serviceRegistry);
            _cache.Add(typeof(IServiceHealthCheck), serviceRegistry);
            _cache.Add(typeof(IServiceHealthCheckCreator), new ServiceHealthCheckCreator(serverConfig.ServiceCheck));
            _cache.Add(typeof(IServerController), new ThriftServerController());
            _cache.Add(typeof(IServiceActivator), new ThriftServiceActivator());

            _cache.Add(typeof(IServiceAssembliesResolver), new ThriftServiceAssembliesResolver());
            _cache.Add(typeof(IServiceFinder), new ThriftServiceFinder());
            _cache.Add(typeof(IServiceDiscoverer), new ThriftServiceDiscoverer());
            _cache.Add(typeof(IThriftClientActivator), new ThriftClientActivator());
            _cache.Add(typeof(IThriftConnectionPool), new FreshConnectionPool());
            //_cache.Add(typeof(IThriftConnectionPool),
            //    new ThriftConnectionPool(clientConfig.ConnectionLimit.Value,
            //                                             clientConfig.WaitFreeMillisecond.Value,
            //                                             clientConfig.WaitFreeTimes.Value,
            //                                             clientConfig.ConnectionOverdueInterval.Value));
            _cache.Add(typeof(IClientController), new ThriftClientController());
            _cache.Add(typeof(IDynamicProxyBuilder), new ThriftDynamicProxy("Mistong.RPCFramework.Thrift"));
            this.AddFilter(new FilterInfo {
                Instance = new MissingResultExceptionFilter(), Order = int.MaxValue
            });
        }