Esempio n. 1
0
        public bool SendMessage(MQProtocol <M> message, string hostName)
        {
            var routeKey = GetRouter(message.RouterKey, hostName);
            var host     = MQHostConfigManager.GetHost(hostName);

            return(GrantMQManager <M> .Publish(message, routeKey, host));
        }
Esempio n. 2
0
        /// <summary>
        /// Local的配置
        /// 系统的所有的基础性配置都会在这里初始化
        /// </summary>
        /// <param name="configuration">本地配置json</param>
        private static void UpdateLocal(Configuration configuration)
        {
            // ServerSetting的初始化依赖配置驱动的,只有配置了才会被初始化,如果某个微服务未使用到某个配置,不配置即可,这样可以做到按需初始化
            try
            {
                if (configuration.DataBase != null)
                {
                    var dbstr = string.Format(dbXMl, configuration.DataBase.RefFile, configuration.DataBase.DbFile);
                    if (!string.IsNullOrEmpty(dbstr))
                    {
                        XElement xml = XElement.Parse(dbstr);
                        DbModelContextManager.Initlize(xml); // 初始化数据库配置和sql脚本
                    }
                }

                ConfigManager.Initlize(configuration.ConstKeyValue);  // 初始化常量

                CacheManager.Initlize(configuration.RedisConfig);     // 初始化redis
                MQHostConfigManager.Initlize(configuration.RabbitMQ); // 是时候MQ
                FileServerManager.Initlize(configuration.FileServer); // 初始化文件服务器
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"ServerSetting.UpdateLocal.Error");
                throw ex;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 保存异步消息,并设置初始处理状态
        /// </summary>
        /// <param name="valueArgs">参数</param>
        /// <returns>是否成功</returns>
        public static bool SetMessage(T valueArgs)
        {
            if (valueArgs == null)
            {
                return(true);
            }

            var msg      = new MQProtocol <T>("AuditMessage", valueArgs, Guid.NewGuid().ToString("N"));
            var routeKey = GetRouter(valueArgs.Ttid);
            var host     = MQHostConfigManager.GetHost("Audit");
            var mq       = GrantMQManager <T> .Publish(msg, routeKey, host);

            return(mq);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the  class.
        /// 创建接受消息实例
        /// </summary>
        /// <param name="groups">接受消息的所有Ttid</param>
        /// <param name="pull">拉消息</param>
        public AuditMessageMgr(bool pull, params string[] groups)
        {
            var host = MQHostConfigManager.GetHost("Audit");

            if (host == null)
            {
                throw new Exception("RabbitMQ 没有配置  Audit 主机!!");
            }

            if (!pull)
            {
                // 订阅所有的routerKey
                foreach (var item in groups)
                {
                    GrantMQManager <T> .ConsumeRegister(
                        GetRouter(item),
                        GetQueue(item),
                        host,
                        true,
                        (MQProtocol <T> m, Exception ex) =>
                    {
                        if (this.OnAuditMessageReceive != null)
                        {
                            return(this.OnAuditMessageReceive(m, ex));
                        }
                        return(false);    // 如果没有回调,不能随意删除消息
                    });
                }
            }
            else
            {
                if (groups.Length > 0)
                {
                    Debug.Assert(true);
                }

                var item = typeof(T).Name;

                // 订阅所有的routerKey
                this._consumer = GrantMQManager <T> .PullConsumeRegister(
                    GetRouter(item),
                    GetQueue(item),
                    host,
                    true);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 按推送节点更新
        /// </summary>
        /// <param name="path">变更路径</param>
        private static void UpdateZookeeper(string path, string configData)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (string.IsNullOrEmpty(configData))
            {
                return;
            }

            logger.LogDebug($"更新路径:{path},更新内容:{configData}");

            try
            {
                lock (_objLock)
                {
                    string[] ps = path.Split("/", StringSplitOptions.RemoveEmptyEntries);
                    switch (ps[ps.Length - 1])
                    {
                    case DbModelContextManager.DATABASE:     // 数据库,从zookeeper推过来的直接就是数据库和脚本的xml内容,这个跟文件有区别,文件是通过 ref引到外部文件的
                                                             // DataBase db = Newtonsoft.Json.JsonConvert.DeserializeObject<DataBase>(configData);
                        var xmlStr = XElement.Parse(configData);
                        DbModelContextManager.Initlize(xmlStr);

                        // Config.DataBase = db; // 把本地的完整配置更新,数据库配置不需要更新全局
                        break;

                    case ConfigManager.CONSTKEYVALUE:     // 常量
                        var keyValue =
                            Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        ConfigManager.Initlize(keyValue.ConstKeyValue);
                        Config.ConstKeyValue = keyValue.ConstKeyValue;
                        break;

                    case CacheManager.RedisConfig:     // redis
                        var redisConfig =
                            Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        CacheManager.Initlize(redisConfig.RedisConfig);
                        Config.RedisConfig = redisConfig.RedisConfig;
                        break;

                    case MQHostConfigManager.RabbitMQ:     // rabbitMQ
                        var mq = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        MQHostConfigManager.Initlize(mq.RabbitMQ);
                        Config.RabbitMQ = mq.RabbitMQ;
                        break;

                    case FileServerManager.FileServerName:     // fileserver
                        var fs = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        FileServerManager.Initlize(fs.FileServer);
                        Config.FileServer = fs.FileServer;
                        break;

                    case SuperGMS.HttpProxy.SuperHttpProxy.HttpProxy:     //HttpProxy
                        var pxyName = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        Config.HttpProxy = pxyName.HttpProxy;
                        break;
                    }

                    updateConfigurationAction?.Invoke(ps[ps.Length - 1], Config); // 执行用户自定义的回调,目前只有log在用,其他不用
                }
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, $"ServerSetting.UpdateZookeeper.Error.path={path},configData={configData}");
            }
        }