我在我的.NET Core应用程序中使用RabbitClient作为队列读取器单例(发布到队列通过其他应用程序)。一段时间后,我的应用程序停止从队列中读取,我遇到了问题。我看到队列中充满了消息,我推的越来越多,但读者应用程序不会读取,直到我重新启动它。这是RabbitClient的代码:
private readonly IConnection _connection;
public RabbitClient(IMessagingConfiguration configuration)
{
IConnectionFactory connectionFactory = new ConnectionFactory { Uri = _configuration.ConnectionString };
_connection = connectionFactory.CreateConnection();
}
public void OnMessageAsync<T>(Func<T, Task> callback) where T : class
{
T result;
var queueName = _configuration.QueueName;
var channel = _connection.CreateModel();
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, args) =>
{
var json = Encoding.UTF8.GetString(args.Body);
result = JsonConvert.DeserializeObject<T>(json);
callback(result).GetAwaiter().GetResult();
channel.BasicAck(args.DeliveryTag, false);
};
channel.BasicConsume(queue: queueName, noAck: false, consumer: consumer);
}
如何在不停止阅读的情况下强制读者继续阅读?