Example #1
0
        /// <summary>
        /// 获取到ESBConfig
        /// </summary>
        /// <returns></returns>
        private ESBConfig GetESBConfig(ConsumerConfig consumerConfig)
        {
            ESBConfig esbConfig = new ESBConfig();
            esbConfig.Service.Add(new ServiceItem() { ServiceName = "ESB_ASHX", DirectInvokeEnabled = true, Uri = "http://esb.jn.com" });


            return esbConfig;
        }
Example #2
0
 /// <summary>
 /// 将ESBConfig配置信息写入磁盘
 /// </summary>
 /// <param name="consumerConfig"></param>
 public void SaveESBConfig(ESBConfig esbConfig)
 {
     try
     {
         File.WriteAllText(ESBConfigPath, XmlUtil.SaveXmlFromObj <ESBConfig>(esbConfig));
     }
     catch (Exception ex)
     {
         XTrace.WriteLine("序列化ESBConfig.xml文件失败:{0}", ex.ToString());
     }
 }
Example #3
0
        /// <summary>
        /// 构造器
        /// </summary>
        public RabbitQueueManager()
        {
            m_EsbConfig = m_ESBProxy.RegistryConsumerClient.ESBConfig;
            m_ConsumerConfig = m_ESBProxy.RegistryConsumerClient.ConsumerConfig;
            m_QueueThreadDict = new Dictionary<String, QueueThread>();
            
            if (m_EsbConfig != null && m_EsbConfig.MessageQueue.Count > 0)
            {
                //String esbQueue = Config.GetConfig<String>("ESB.Queue");
                String esbQueue = m_EsbConfig.MessageQueue[0].Uri;
                XTrace.WriteLine("读取到ESB队列地址:{0}", esbQueue);

                m_ParamMQ = esbQueue.Split(':');
            }
            else
            {
                String err = "无法获取到有效的队列地址!";
                XTrace.WriteLine(err);
                throw new Exception(err);
            }
        }
Example #4
0
        /// <summary>
        /// 获取到ESBConfig
        /// </summary>
        /// <returns></returns>
        private ESBConfig GetESBConfig(RegistryClient regClient)
        {
            ConsumerConfig consumerConfig = regClient.ConsumerConfig;
            ESBConfig esbConfig = new ESBConfig();

            //--处理中心地址
            foreach (SettingUri uri in SettingUri.FindAll())
            {
                switch (uri.UriType)
                {
                    case 0: //--注册中心
                        esbConfig.Registry.Add(new RegistryItem() { Uri = String.Format("{0}:{1}", uri.Uri, uri.Port), Load = 1 });
                        break;
                    case 1: //--监控中心
                        esbConfig.Monitor.Add(new MonitorItem() { Uri = String.Format("{0}:{1}", uri.Uri, uri.Port), Load = 1 });
                        break;
                    case 2: //--调用中心
                        esbConfig.CallCenter.Add(new CallCenterItem() { Uri = uri.Uri, Load = 1 });
                        break;
                    case 3: //--队列中心
                        esbConfig.MessageQueue.Add(new MessageQueueItem() { Uri = String.Format("{0}:{1}:{2}:{3}", uri.Uri, uri.Port, uri.UserName, uri.PassWord), Load = 1 });
                        break;
                    case 4: //--缓存中心
                        esbConfig.Cache.Add(new CacheItem() { Uri = String.Format("{0}:{1}", uri.Uri, uri.Port), Load = 1 });
                        break;
                    default:
                        break;
                }
            }

            //--处理服务
            if (regClient.RegistryClientType == CometClientType.Consumer
                || regClient.RegistryClientType == CometClientType.Portal
                || regClient.RegistryClientType == CometClientType.Monitor)
            {
                foreach (var refService in consumerConfig.Reference)
                {

                    List<EsbView_ServiceVersion> lstBS = EsbView_ServiceVersion.FindAllPublish();
                    foreach(EsbView_ServiceVersion bs in lstBS.Where(x=>x.ServiceName == refService.ServiceName))
                    {
                        ServiceItem si = new ServiceItem();
                        si.ServiceName = bs.ServiceName;
                        si.Version = bs.BigVer;
                        si.Binding = bs.Binding;
                        si.IsDefault = (bs.BigVer == bs.DefaultVersion);

                        esbConfig.Service.Add(si);
                    }
                }
            }
            else if(regClient.RegistryClientType == CometClientType.CallCenter 
                || regClient.RegistryClientType == CometClientType.QueueCenter)
            {
                EntityList<EsbView_ServiceVersion> lstBS = EsbView_ServiceVersion.FindAllPublish();
                foreach (var bs in lstBS)
                {
                    ServiceItem si = new ServiceItem();
                    si.ServiceName = bs.ServiceName;
                    si.Version = bs.BigVer;
                    si.Binding = bs.Binding;
                    si.IsDefault = (bs.BigVer == bs.DefaultVersion);

                    esbConfig.Service.Add(si);
                }
            }

            //--处理服务配置
            if (regClient.RegistryClientType == CometClientType.Consumer
                || regClient.RegistryClientType == CometClientType.Portal
                || regClient.RegistryClientType == CometClientType.Monitor)
            {

                List<EsbView_ServiceConfig> lstSC = EsbView_ServiceConfig.FindAll();

                foreach (var refService in consumerConfig.Reference)
                {
                    List<EsbView_ServiceConfig> scs = lstSC.FindAll(x => x.ServiceName == refService.ServiceName);
                    foreach (EsbView_ServiceConfig sc in scs)
                    {
                        esbConfig.ServiceConfig.Add(sc);
                    }
                }
            }
            else if (regClient.RegistryClientType == CometClientType.CallCenter
                || regClient.RegistryClientType == CometClientType.QueueCenter)
            {
                esbConfig.ServiceConfig = EsbView_ServiceConfig.FindAll();
            }


            return esbConfig;
        }
Example #5
0
 /// <summary>
 /// 订阅注册中心的服务变化事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RegistryConsumerClient_OnServiceConfigChange(object sender, ESB.Core.Registry.RegistryEventArgs e)
 {
     m_EsbConfig = e.ESBConfig;
     ConfigQueueThread();
 }
Example #6
0
 /// <summary>
 /// 将ESBConfig配置信息写入磁盘
 /// </summary>
 /// <param name="consumerConfig"></param>
 public void SaveESBConfig(ESBConfig esbConfig)
 {
     try
     {
         File.WriteAllText(ESBConfigPath, XmlUtil.SaveXmlFromObj<ESBConfig>(esbConfig));
     }
     catch (Exception ex)
     {
         XTrace.WriteLine("序列化ESBConfig.xml文件失败:{0}", ex.ToString());
     }
 }
Example #7
0
        /// <summary>
        /// 加载配置文件:加载本地配置文件ConsumerConfig->ESBConfig
        /// </summary>
        private void LoadConfig()
        {
            m_ConfigurationManager = ConfigurationManager.GetInstance();
            m_ConsumerConfig = m_ConfigurationManager.LoadConsumerConfig();
            m_ESBConfig = m_ConfigurationManager.LoadESBConfig();

            if (m_ConsumerConfig == null)
                throw new Exception("缺少有效的消费者配置文件ConsumerConfig.xml。");

            if (m_ESBConfig == null)
                Status = ESBProxyStatus.LostESBConfig;
            else
                Status = ESBProxyStatus.Ready;
        }