Exemplo n.º 1
0
        public static void ExposeService <T, TImpl>() where TImpl : class
        {
            var serviceMetta = new ServiceRegistryMetta
            {
                InstanceType  = typeof(TImpl).AssemblyQualifiedName,
                InterfaceType = typeof(T).AssemblyQualifiedName,
                Protocol      = AppEnv.GlobalConfiguration.ProviderConfiguration.Protocol,
                SerializeMode = AppEnv.GlobalConfiguration.ProviderConfiguration.SerializeMode,
                ApiDomain     = AppEnv.GlobalConfiguration.ProviderConfiguration.ApiDomain,
                ServerAddress = AppEnv.GlobalConfiguration.ProviderConfiguration.ApiIpAddress,
                IsEnabled     = true,
                Attributes    = DictionaryUtils.GetFromConfig(AppEnv.GlobalConfiguration.ProviderConfiguration.AddtionalFields)
            };

            ExposeService <T, TImpl>(serviceMetta);
        }
Exemplo n.º 2
0
        public RedisRegistryProvider()
        {
            if (SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration == null)
            {
                throw new Exception("注册中心配置有误");
            }

            string url            = SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration.Url;
            string collectionName = "RegistryData";

            var attrs = DictionaryUtils.GetFromConfig(SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration.AddtionalFields);

            if (attrs != null && attrs.ContainsKey(AttrKeys.Registry_RedisCollectionName))
            {
                if (!string.IsNullOrEmpty(attrs[AttrKeys.Registry_RedisCollectionName]))
                {
                    collectionName = attrs[AttrKeys.Registry_RedisCollectionName];
                }
            }

            _redisClient = new RedisClient(url);
            _typedClient = _redisClient.As <RegistryDataInfo>();
            _table       = _typedClient.Lists[collectionName];

            _redisSubscription            = _redisClient.CreateSubscription();
            _redisSubscription.OnMessage += (channel, msg) =>
            {
                var data = _serializer.Deserialize <ServiceRegistryMetta>(msg);
                if (this.ServiceChanged == null)
                {
                    return;
                }

                this.ServiceChanged(this, new ServiceNotifyEventArgs
                {
                    Data = data
                });
            };
        }