Esempio n. 1
0
        internal void Receive(object sender, BasicDeliverEventArgs e)
        {
            MessageBody body = new MessageBody();

            try
            {
                string content = MQConnection.UTF8.GetString(e.Body);
                body.Content      = content;
                body.Consumer     = (EventingBasicConsumer)sender;
                body.BasicDeliver = e;
            }
            catch (Exception ex)
            {
                body.ErrorMessage = $"订阅-出错{ex.Message}";
                body.Exception    = ex;
                body.Error        = true;
                body.Code         = 500;
            }
            OnReceivedCallback?.Invoke(body);
        }
Esempio n. 2
0
 /// <summary>
 /// 接收消息
 /// </summary>
 /// <param name="message"></param>
 public override void OnReceived(MessageBody message)
 {
     //如果不返回ACK 则 RabbitMQ 不会再发送数据
     message.Consumer.Model.BasicAck(message.BasicDeliver.DeliveryTag, true);
     if (string.IsNullOrEmpty(message.Content))
     {
         return;
     }
     try
     {
         DataChange data   = message.Content.JsonToObject <DataChange>();
         var        result = _dbTypeMapper.TransferToDb(data);
         if (!result.Success)
         {
             OnAction?.Invoke(MessageLevel.Error, $"TransferToDb Error", new Exception(result.Msg));
         }
     }
     catch (Exception ex)
     {
         OnAction?.Invoke(MessageLevel.Error, ex.Message + $"【{message.Content}】", ex);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 接收消息
 /// </summary>
 /// <param name="message"></param>
 public abstract void OnReceived(MessageBody message);