Пример #1
0
        /// <summary>
        /// 处理消息句柄接口
        /// </summary>
        /// <param name="args"></param>
        /// <returns>
        /// 返回值为true,则指示消息需要加入队列被重新消费处理
        /// </returns>
        public bool?ReceiveHandler(IncomingMsgEventArgs args)
        {
            if (args.IsDuplicate)
            {
                logger.Debug($"RCV {args.ConsumerTag} {args.TopicFullOrRoutingKey} {args.DeliveryTag} IsDuplicate, no process @{args.Body}");
                return(default(bool?));
            }

            return(this.ProcessWrapperReturn(args));
        }
Пример #2
0
        private bool?Context_OnReceived(IncomingMsgEventArgs e)
        {
            bool?rst = false;

            //if (!string.IsNullOrEmpty(e.TopicName) && handlerMap.ContainsKey(e.TopicName))
            if (true)
            {
                // rst = handlerMap[e.TopicName].ReceiveHandler(e);
                rst = handlerMap["DiagnosticResult"].ReceiveHandler(e);
            }
            else
            {
                logger.Error($"RCV routingkey[{e.TopicFullOrRoutingKey}] and topicname[{e.TopicName}] is not config the process handler");
                rst = false;     ////无法识别的消息直接忽略, 目前尚未考虑死信队列
            }

            return(rst);
        }
Пример #3
0
        private void _consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            var args = new IncomingMsgEventArgs(e.RoutingKey, e.Body, e.Redelivered);

            logger.Debug($"RCV {e.ConsumerTag} {e.RoutingKey} {e.DeliveryTag} @{args.Body}");

            bool?rst = default(bool?);

            args.ConsumerTag = e.ConsumerTag;
            args.DeliveryTag = e.DeliveryTag;
            rst = this.OnReceived(args);

            if (!this.autoAck)
            {
                var model = ((IBasicConsumer)sender).Model;
                try
                {
                    if (!model.IsClosed && model.IsOpen)
                    {
                        if (rst.HasValue && rst.Value)
                        {
                            model.BasicReject(e.DeliveryTag, false);        ////当确定调用业务方法处理消息失败时,不会重新加入队列,为死信做准备
                            logger.Debug($"{ e.RoutingKey} {e.DeliveryTag} reject to quque");
                        }
                        else
                        {
                            model.BasicAck(e.DeliveryTag, false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("model[{model.ChannelNumber}] ack {e.RoutingKey} message[{e.DeliveryTag}] exception");
                    logger.Error(ex);
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 处理消息句柄接口
 /// </summary>
 /// <param name="args"></param>
 /// <returns>
 /// 当Protocol是AMQP时,返回值为true,则指示消息需要加入队列被重新消费处理
 /// 默认请返回 false 表示消息处理完成,不需要重复处理
 /// </returns>
 protected abstract bool?Process(IncomingMsgEventArgs args);