Beispiel #1
0
        /// <summary>
        /// 消息接收
        /// </summary>
        internal async void Receive(object sender, BasicDeliverEventArgs e)
        {
            MessageBody body = null;

            try
            {
                body = new MessageBody
                {
                    Consumer     = (EventingBasicConsumer)sender,
                    BasicDeliver = e
                };
                try
                {
                    body.Content = ByteDerialize(e.Body);
                    _logger.Debug(body.Content);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "订阅出错");
                    body.Content      = $"订阅出错|{ex.Message}";
                    body.ErrorMessage = $"订阅出错|{ex.Message}";
                    body.Exception    = ex;
                }
                await OnReceivedCallback?.Invoke(body);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "订阅出错");
                try
                {
                    body?.BasicAck();
                }
                catch (Exception ex2)
                {
                    _logger.Error(ex2, "订阅出错");
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 接收消息
 /// </summary>
 /// <param name="message"></param>
 public abstract Task OnReceived(MessageBody message);