Beispiel #1
0
        /// <summary>
        /// 配置接收RabbitMQ推送信息
        /// </summary>
        /// <returns></returns>
        private static void RabbitMQRecive()
        {
            var envname = SystemJsonConfigManage.GetInstance().SoaConfigInfo.EnvName;
            var ex      = bus.Advanced.ExchangeDeclare("bt_configDataCenter", ExchangeType.Direct);
            var qu      = bus.Advanced.QueueDeclare();

            bus.Advanced.Bind(ex, qu, envname + "_" + _configoptionDto.APPKey);
            bus.Advanced.Consume(qu, (body, properties, info) => Task.Factory.StartNew(() =>
            {
                try
                {
                    lock (lockHelper)
                    {
                        var message = Encoding.UTF8.GetString(body);
                        //处理消息
                        var value     = JsonConvert.DeserializeObject <ConfigValue>(message);
                        var valuelist = new List <ConfigValue>();
                        valuelist.Add(value);
                        //同步配置
                        _josnConfigMan.WiteConfig(valuelist);
                    }
                }
                catch (Exception e)
                {
                    LogService.Default.Fatal(e, "接收配置中心数据出错:" + e.Message);
                    throw e;
                }
            }));
        }
 public static SystemJsonConfigManage GetInstance()
 {
     lock (locker)//确保线程安全
     {
         if (_configManage == null)
         {
             _configManage = new SystemJsonConfigManage();
             _configManage.configOperat = new ConfigurationBuilder()
                                          .AddInMemoryCollection()
                                          .SetBasePath(Directory.GetCurrentDirectory())
                                          .AddJsonFile(_configManage.basejsonFileName, optional: true, reloadOnChange: true)
                                          .Build();
         }
         return(_configManage);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 启用数据中心
 /// </summary>
 public static void UserConfigDataCenter(IBus _bus, string serverName)
 {
     try
     {
         bus = _bus;
         _configoptionDto = new ConfigOptionsDto
         {
             APPKey           = serverName,
             IsEnableLooppull = SystemJsonConfigManage.GetInstance().AppSettings["IsEnableLooppull"].ToSafeBool(true),
             ConsulDataCenter = SystemJsonConfigManage.GetInstance().SoaConfigInfo.DataCenterName,
             ConsulHost       = "http://" + SystemJsonConfigManage.GetInstance().SoaConfigInfo.WriteServer,
             ENVKey           = SystemJsonConfigManage.GetInstance().SoaConfigInfo.EnvName,
             ConsulTimeOut    = SystemJsonConfigManage.GetInstance().SoaConfigInfo.ConnectTimeOut,
             ConsulWaitTime   = 30
         };
         RabbitMQRecive();
         Looppull();
     }
     catch (Exception ex)
     {
         LogService.Default.Fatal(ex, "启用配置中心出错" + ex.Message);
     }
 }