Пример #1
0
 public override async void UserEventTriggered(IChannelHandlerContext context, object evt)
 {
     try
     {
         if (evt is IdleStateEvent)
         {
             PerformanceCounter cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
             var percentage         = cpu.NextValue();
             Volatile.Read(ref percentage);
             percentage = cpu.NextValue();
             GlobalMemoryStatus(ref MemInfo);
             var memory = MemInfo.dwMemoryLoad;
             var msg    = $"{percentage},{memory},{{{string.Join(",", string.Empty)}}}";
             _logWriter?.Info($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff")}:{msg}");
             HEARTBEAT_SEQUENCE = Unpooled.UnreleasableBuffer(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("HEARTBEAT:" + msg)));
             try
             {
                 await context.WriteAndFlushAsync(HEARTBEAT_SEQUENCE.Duplicate());
             }
             catch (Exception e)
             {
                 _logWriter?.Fatal($"{nameof(HeartbeatHandler)}.{nameof(UserEventTriggered)}:{e}");
             }
         }
         else
         {
             base.UserEventTriggered(context, evt);
         }
     }
     catch (Exception e)
     {
         _logWriter?.Fatal($"{nameof(HeartbeatHandler)}.{nameof(UserEventTriggered)}:{e}");
     }
 }
Пример #2
0
        public void HandleMessage(int Pid, string content, ILogWriter _log)
        {
            _log.Info("收到一条消息处理请求:" + content);
            //拆分字符串并拼json
            var arrContent = content.Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries);

            var center = ConfigurationManager.AppSettings["MessageCenter"];

            //如果不是文字、图片消息,就直接返回
            if (arrContent[3].IndexOf("no") > -1)
            {
                return;
            }

            Task.Run(() =>
            {
                string msgContent = "";
                if (arrContent[3].IndexOf("image") > -1)
                {
                    string u1 = GetImageBaseDir() + arrContent[4];
                    u1        = u1.Substring(0, u1.LastIndexOf(".dat") + 4);//防止后面有乱码
                    try
                    {
                        _log.Info(u1 + "\r\n");
                        //解密图片
                        msgContent = DecryptImageHelper.Decrypt(u1);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("解密图片时候报错:" + ex.Message + u1);
                    }
                }
                else
                {
                    msgContent = arrContent[2];
                }

                var jsonObj = new
                {
                    GroupId    = arrContent[0],
                    MemberId   = arrContent[1],
                    MsgTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff"),
                    MsgContent = msgContent,
                    MsgType    = arrContent[3]
                };
                _log.Fatal(msgContent);
                var jsonContent = JsonSerializeHelper.JsonSerialize(jsonObj);
                //发送到数据接口
                //new WebHelper().PostMessage(center, jsonContent, _log);
                //调用微信群组接口
                //ChatRoomMember.GetChatRoomUser(Pid, jsonObj.GroupId);
                ChatRoomMember.SendRoomAtMsg(Pid, arrContent[0]);
            });
        }
Пример #3
0
 private void Connect()
 {
     try
     {
         _connection?.Dispose();
         _connection = _connectionFactory.CreateConnection();
         Channel     = _connection.CreateModel();
     }
     catch (Exception ex)
     {
         _logWriter.Fatal("error establishing connection", ex);
     }
 }
Пример #4
0
        public void TryConnect()
        {
            _connection?.Dispose();
            _connection = _connectionFactory.CreateConnection();

            if (IsConnected)
            {
                _connection.ConnectionShutdown += OnConnectionShutdown;
                _connection.CallbackException  += OnCallbackException;
                _connection.ConnectionBlocked  += OnConnectionBlocked;

                return;
            }

            _logWriter.Fatal("RabbitMQ connections could not be created and opened");
        }