Пример #1
0
 private void ConsumerOnListener(TopicName topicName, IMessage message)
 {
     try
     {
         ActiveMQTextMessage msg = (ActiveMQTextMessage)message;
         var clientId            = GetClientId(msg);
         if (clientId == null || clientId == Guid.Empty)
         {
             _logger.Error(string.Format("topicName:{0} ConsumerOnListener无效客户端,数据直接抛弃 IP:{1}:{2}", topicName, _configInfo.IpAddress, _configInfo.Port));
             return;
         }
         var            msgType     = message.NMSType;
         NMSMessageType messageType = NMSMessageType.None;
         if (!string.IsNullOrEmpty(msgType))
         {
             messageType = Utils.GetEnum <NMSMessageType>(msgType);
         }
         MqCommandInfo commandInfo = new MqCommandInfo()
         {
             StoreId      = clientId.Value,
             Body         = msg.Text,
             Length       = msg.Size(),
             MessageType  = messageType,
             RawNMSType   = msgType,
             NMSMessageId = msg.NMSMessageId,
             MqInstancId  = _configInfo.MqInstanceId,
             ClientId     = this.ClientId,
             Properties   = new Dictionary <string, string>(),
         };
         if (msg.Properties != null)
         {
             foreach (var key in msg.Properties.Keys)
             {
                 if (key == null)
                 {
                     continue;
                 }
                 var keystr = key.ToString();
                 if (!commandInfo.Properties.ContainsKey(keystr))
                 {
                     commandInfo.Properties.Add(keystr, msg.Properties.GetString(keystr));
                 }
             }
         }
         OnTopicDispatch(topicName, commandInfo);
         if (commandInfo.ExcuteCount == 0)
         {
             _logger.Error(string.Format("消息未找到处理程序 类型: {0}大小: {1}", commandInfo.MessageType, commandInfo.Length));
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "主题消费者监听事件处理.ConsumerOnListener");
     }
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        protected virtual void OnTopicDispatch(TopicName arg1, MqCommandInfo arg2)
        {
            var handler = TopicDispatch;

            if (handler != null)
            {
                handler(arg1, arg2);
            }
            else
            {
                _logger.Error("未找到主题消息分配处理程序");
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        protected virtual void OnQuqueDispatch(QuqueName arg1, MqCommandInfo arg2)
        {
            var handler = QuqueDispatch;

            if (handler != null)
            {
                handler(arg1, arg2);
            }
            else
            {
                _logger.Error("未找到队列消息分配处理程序");
            }
        }
        private void ServiceOnQuqueDispatch(QuqueName ququeName, MqCommandInfo commandInfo)
        {
            foreach (var mqCommandTopicVistor in _queueVistors)
            {
                commandInfo.ExcuteCount++;
                mqCommandTopicVistor.Vistor(ququeName, commandInfo);
            }
            ExcuteInfo info;

            _excuteInfoDictionary.TryGetValue(commandInfo.ClientId, out info);
            if (info != null)
            {
                lock (LockExcuteInfoObj)
                {
                    info.TotalCount++;
                    info.TotalSize += commandInfo.Length;
                }
            }
        }
Пример #5
0
 private void ConsumerOnListener(QuqueName ququeName, IMessage message)
 {
     try
     {
         string msgContext = "";
         if (message is ActiveMQBytesMessage)
         {
             bool isZipCompress = false;
             if (message.Properties.Contains(MqConsts.IsZipCompress))
             {
                 isZipCompress = message.Properties.GetBool(MqConsts.IsZipCompress);
             }
             ActiveMQBytesMessage msg = (ActiveMQBytesMessage)message;
             if (isZipCompress)
             {
                 msgContext = StringZipHelper.GZipDecompress(msg.Content);
             }
             else
             {
                 msgContext = System.Text.Encoding.UTF8.GetString(msg.Content);
             }
         }
         else if (message is ActiveMQTextMessage)
         {
             ActiveMQTextMessage msg = (ActiveMQTextMessage)message;
             msgContext = msg.Text;
         }
         else
         {
             _logger.Error("消费者监听事件处理错误.暂时只接受ActiveMQBytesMessage、ActiveMQTextMessage消息体");
         }
         var clientId = GetClientId(message);
         if (clientId == Guid.Empty || clientId == null)
         {
             _logger.Error(string.Format("消息无效,没有匹配的门店与命令号 "));
             return;
         }
         var            msgType     = message.NMSType;
         NMSMessageType messageType = NMSMessageType.None;
         if (!string.IsNullOrEmpty(msgType))
         {
             messageType = Utils.GetEnum <NMSMessageType>(msgType);
         }
         MqCommandInfo commandInfo = new MqCommandInfo()
         {
             StoreId      = clientId.Value,
             Body         = msgContext,
             Length       = msgContext.Length,
             MessageType  = messageType,
             NMSMessageId = message.NMSMessageId,
             MqInstancId  = _configInfo.MqInstanceId,
             ClientId     = this.ClientId,
             Properties   = new Dictionary <string, string>()
         };
         if (message.Properties != null)
         {
             foreach (var key in message.Properties.Keys)
             {
                 if (key == null)
                 {
                     continue;
                 }
                 var keystr = key.ToString();
                 if (!commandInfo.Properties.ContainsKey(keystr))
                 {
                     commandInfo.Properties.Add(keystr, message.Properties.GetString(keystr));
                 }
             }
         }
         OnQuqueDispatch(ququeName, commandInfo);
         if (commandInfo.ExcuteCount == 0)
         {
             _logger.Error(string.Format("消息未找到处理程序 类型: {0}大小: {1}", commandInfo.MessageType, commandInfo.Length));
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "消费者监听事件处理错误.ConsumerOnListener");
     }
 }