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
上一篇: Access创建一个简单MIS管理系统