Skip to content

Commit

Permalink
Try to fixes RabbitMQ BasicConsume TimeOutException . #1405
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Sep 21, 2023
1 parent adbe7bf commit c63fa87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ public void Listening(TimeSpan timeout, CancellationToken cancellationToken)
consumer.ConsumerCancelled += OnConsumerConsumerCancelled;

if (_rabbitMQOptions.BasicQosOptions != null)
_channel?.BasicQos(0, _rabbitMQOptions.BasicQosOptions.PrefetchCount,
_rabbitMQOptions.BasicQosOptions.Global);
_channel?.BasicQos(0, _rabbitMQOptions.BasicQosOptions.PrefetchCount, _rabbitMQOptions.BasicQosOptions.Global);

_channel.BasicConsume(_queueName, false, consumer);
try
{
_channel.BasicConsume(_queueName, false, consumer);
}
catch (TimeoutException ex)
{
OnConsumerShutdown(null, new ShutdownEventArgs(ShutdownInitiator.Application, 0, ex.Message + "-->" + nameof(_channel.BasicConsume)));
}

while (true)
{
Expand Down Expand Up @@ -121,7 +127,14 @@ public void Connect()
if (!string.IsNullOrEmpty(_rabbitMQOptions.QueueArguments.QueueType))
arguments.Add("x-queue-type", _rabbitMQOptions.QueueArguments.QueueType);

_channel.QueueDeclare(_queueName, true, false, false, arguments);
try
{
_channel.QueueDeclare(_queueName, true, false, false, arguments);
}
catch (TimeoutException ex)
{
OnConsumerShutdown(null, new ShutdownEventArgs(ShutdownInitiator.Application, 0, ex.Message + "-->" + nameof(_channel.QueueDeclare)));
}
}
}
}
Expand Down

0 comments on commit c63fa87

Please sign in to comment.