Beispiel #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="mq">消息实体内容</param>
        /// <param name="messageType">消息类型</param>
        /// <returns></returns>
        public bool SendMessage(Common.Mode.MQModel mq, Common.MessageType messageType)
        {
            try
            {
                System.Threading.Interlocked.Increment(ref _instanceNumber);

                if (messageType == Common.MessageType.Ack)
                {
                    string str = Newtonsoft.Json.JsonConvert.SerializeObject(mq);
                    AckMessageQueue.Enqueue(Common.MQTools.GetMQDataInfoMessage((byte)Common.CommanCode.SendMessage, str, _instanceNumber, mqType: 1));
                    Logger.Debug($"发送【确认】消息 编号:【{_instanceNumber}】内容:【{str}】放入消息队列【{AckMessageQueue.Count}】");
                    //消息队列获取消息
                    //var msg = AckMessageQueue.Peek();
                    //byte[] buffer;
                    //msg.GetSendByte(out buffer);
                    //Logger.Info($"发送【确认】消息 内容:【{msg}】当前队列长度:【{AckMessageQueue.Count}】");
                    //easyClient.Send(buffer);
                }
                else
                {
                    string str = Newtonsoft.Json.JsonConvert.SerializeObject(mq);
                    Logger.Info($"发送【普通】消息 编号:【{_instanceNumber}】内容:【{str}】");
                    var msg = Common.MQTools.GetSendMessage((byte)Common.CommanCode.SendMessage, str, _instanceNumber, mqType: (byte)messageType);
                    easyClient.Send(msg);
                }

                return(true);
            }
            catch (Exception e)
            {
                System.Threading.Interlocked.Decrement(ref _instanceNumber);
                Logger.Error(mq, e);
                return(false);
            }
        }
Beispiel #2
0
        private static void MQHelp_OnMessageArrive(object sender, Common.Mode.MQModel e)
        {
            var t = (DateTime.Now - e.CreatDate).TotalMilliseconds;

            list.Add(t);

            log.Info($"消息终端: {e.SenderId} 主题: {e.Topic} 标签: {e.Tag} 消息内容: {e.Attachment} 时间: {e.CreatDate.ToString("yyyy-MM-dd HH:mm:ss,fff")} 耗时:{(t / 1000)}(毫秒/ms) 平均耗时:{(list.Sum() / list.Count / 1000)}(毫秒/ms) 采样数据个数:{list.Count}");
        }
Beispiel #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="mq">消息实体内容</param>
        /// <returns></returns>
        public bool SendMessage(Common.Mode.MQModel mq)
        {
            try
            {
                string str = Newtonsoft.Json.JsonConvert.SerializeObject(mq);
                System.Threading.Interlocked.Increment(ref _instanceNumber);
                Logger.Info($"发送【普通】消息 编号:【{_instanceNumber}】内容:【{str}】");
                var msg = Common.MQTools.GetSendMessage((byte)Common.CommanCode.SendMessage, str, _instanceNumber, mqType: 0);

                easyClient.Send(msg);

                return(true);
            }
            catch (Exception e)
            {
                System.Threading.Interlocked.Decrement(ref _instanceNumber);
                Logger.Error(mq, e);
                return(false);
            }
        }