Beispiel #1
0
        /// <summary>
        /// 接受到消息。
        /// </summary>
        private void consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            try
            {
                //EventLog.Log("body:" + e.Body, "mq");
                var result = EventMessage.BuildEventMessageResult(e.Body); //获取消息返回对象

                if (_actionMessage.IsNotNull())
                {
                    _actionMessage(result); //触发外部侦听事件
                }
                if (result.IsOperationOk.IsFalse())
                {
                    //未能消费此消息,重新放入队列头
                    Context.ListenChannel.BasicReject(e.DeliveryTag, true);
                }
                else if (Context.ListenChannel.IsClosed.IsFalse())
                {
                    Context.ListenChannel.BasicAck(e.DeliveryTag, false);
                }
            }
            catch (Exception exception)
            {
                EventLog.Log("RabbitMQClient=>consumer_Received:" + exception, "mq");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 接受到消息。
        /// </summary>
        private void consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            try
            {
                var result = EventMessage.BuildEventMessageResult(e.Body); //获取消息返回对象

                if (_actionMessage.IsNotNull())
                {
                    _actionMessage(result); //触发外部侦听事件
                }
                if (result.IsOperationOk.IsFalse())
                {
                    //未能消费此消息,重新放入队列头
                    Context.ListenChannel.BasicReject(e.DeliveryTag, true);
                }
                else if (Context.ListenChannel.IsClosed.IsFalse())
                {
                    Context.ListenChannel.BasicAck(e.DeliveryTag, false);
                }
            }
            catch (Exception exception)
            {
                if (LogLocation.Log.IsNotNull())
                {
                    LogLocation.Log.WriteException("TJAP.Common.Tools.MessageQueue", exception);
                }
            }
        }