0
我在我的.NET Core應用程序中使用RabbitClient作爲Queue reader singleton(發佈到隊列通過其他應用程序)。而且在我的應用程序停止從隊列中讀取一段時間後,我正面臨着這個問題。我看到隊列裏充滿了消息,我推得越來越多,但是直到我重新啓動它,閱讀器應用程序纔讀取消息。以下是RabbitClient的代碼:RabbitMQ EventingBasicConsumer停止接收消息
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);
}
我該如何強制讀者在沒有這種停止的情況下繼續閱讀?
當你停止接收消息,並您的消費保持連接到服務器的RabbitMQ?你可以在RabbitMQ管理界面中檢查這個UI –
你使用的是什麼版本的RabbitMQ和.NET客戶端?你是否爲此搜索了[GitHub問題](https://github.com/rabbitmq/rabbitmq-dotnet-client/pull/275)? –