Exemplo n.º 1
0
 /// <summary>
 /// 同步方法:获取到ESBConfig文件
 /// </summary>
 internal void SyncESBConfig()
 {
     lock (m_SyncESBConfigLock)
     {
         m_CometClient.SendData(CometMessageAction.Hello, m_ESBProxy.ConsumerConfig.ToXml(), false);
         m_AutoResetEvent.WaitOne();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 接收注册中心的消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void m_CometClient_OnReceiveNotify(object sender, CometEventArgs e)
        {
            try
            {
                if (e.Type == CometEventType.ReceiveMessage)    // 接收到来自服务器的配置信息
                {
                    RegistryMessage rm = XmlUtil.LoadObjFromXML <RegistryMessage>(e.Response);

                    if (rm.Action == RegistryMessageAction.ServiceConfig)
                    {
                        m_ESBProxy.ESBConfig = XmlUtil.LoadObjFromXML <ESBConfig>(rm.MessageBody);
                        ThreadPoolX.QueueUserWorkItem(x =>
                        {
                            m_ConfigurationManager.SaveESBConfig(m_ESBProxy.ESBConfig);
                        });
                    }
                }
                else if (e.Type == CometEventType.Connected)   // 当和服务器取得联系时发送消费者配置文件到服务端
                {
                    m_CometClient.SendData(RegistryMessageAction.Hello, m_ESBProxy.ConsumerConfig.ToXml());
                }
            }
            catch (Exception ex)
            {
                XTrace.WriteLine("接收注册中心消息时发生错误:" + ex.ToString());
            }
        }