Beispiel #1
0
        /// <summary>
        /// 将网络层的通知传递到应用层
        /// </summary>
        /// <param name="notifyType"></param>
        /// <param name="message"></param>
        private void ReceiveNotify(CometEventType notifyType, String message)
        {
            if (OnReceiveNotify != null)
            {
                CometEventArgs e = new CometEventArgs()
                {
                    Type = notifyType, Response = message
                };

                OnReceiveNotify(this, e);
            }
        }
Beispiel #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)    // 接收到来自服务器的配置信息
                {
                    CometMessage rm = XmlUtil.LoadObjFromXML<CometMessage>(e.Response);

                    if (rm.Action == CometMessageAction.Publish)
                    {
                        List<ServiceMonitor> lstServiceMonitor = XmlUtil.LoadObjFromXML<List<ServiceMonitor>>(rm.MessageBody);

                        if (OnMonitorStatPublish != null)
                        {
                            OnMonitorStatPublish(this, new MonitorStatEventArgs(lstServiceMonitor));
                        }
                    }
                }
                else if (e.Type == CometEventType.Connected) 
                {
                    XTrace.WriteLine("成功连接到监控中心。");
                }
                else if (e.Type == CometEventType.Lost)     // 当和监控中心断开连接时
                {
                    Console.WriteLine("和监控中心断开连接, 5秒钟后将重新连接。");
                    ReConnect();
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("接收监控中心消息时发生错误:" + ex.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// 将网络层的通知传递到应用层
        /// </summary>
        /// <param name="notifyType"></param>
        /// <param name="message"></param>
        private void ReceiveNotify(CometEventType notifyType, String message)
        {
            if (OnReceiveNotify != null)
            {
                CometEventArgs e = new CometEventArgs() { Type = notifyType, Response = message };

                OnReceiveNotify(this, e);
            }
        }
Beispiel #4
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)    // 接收到来自服务器的配置信息
                {
                    CometMessage rm = XmlUtil.LoadObjFromXML<CometMessage>(e.Response);

                    if(rm.Action == CometMessageAction.ServiceConfig)
                    {
                        OnReceiveServiceConfig(rm);
                    }
                    else if(rm.Action == CometMessageAction.ListRegistryClient)
                    {
                        OnListRegistryClient(rm);
                    }
                }
                else if (e.Type == CometEventType.Connected)   // 当和服务器取得联系时发送消费者配置文件到服务端
                {
                    XTrace.WriteLine("成功连接到注册中心。");
                    m_CometClient.SendData(CometMessageAction.Hello, m_ESBProxy.ConsumerConfig.ToXml());
                }
                else if (e.Type == CometEventType.Lost)     // 当和注册中心断开连接时
                {
                    Console.WriteLine("和注册中心断开连接。");
                    ReConnect();
                }

            }
            catch (Exception ex)
            {
                XTrace.WriteLine("接收注册中心消息时发生错误:" + ex.ToString());
            }
        }