欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

RabbitMQ手动应答

程序员文章站 2022-03-09 08:12:06
protected ConnectionFactory factory; protected IConnection connection; protected IModel channel; protected BasicGetResult q; protected WorkerDAL workerDal; protected bool isMQ = true; protected DataSourceMQ s...
protected ConnectionFactory factory;
        protected IConnection connection;
        protected IModel channel;
        protected BasicGetResult q;
        protected WorkerDAL workerDal;
        protected bool isMQ = true;
        protected DataSourceMQ sourceMQ { get; set; }
        public WorkerBaseAbstract()
        {
            workerDal = new WorkerDAL();
            Connect();
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    if (isMQ) { 
                    q = channel.BasicGet(sourceMQ.QueueName, false);///获取信息改为手动应答
                    if (q != null)
                    {
                        DomainAction();
                    }
                    }
                    else
                    {
                        DomainAction();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("读取MQ消息失败:" + ex.Message);
                }
                await Task.Delay(1000, stoppingToken);
            }
        }
 channel.BasicAck(q.DeliveryTag, false);//手动应答处理

本文地址:https://blog.csdn.net/u012511100/article/details/109637922

相关标签: 笔记 rabbitmq