Can you Add a lock around the publish call.
and Use an AsyncLock or a SemaphoreSlim to serialize access to the _channel:
private readonly SemaphoreSlim _vpublishLock = new(1, 1);
private async Task Publish<T>(T model, string _exchange, string _routingKey)
{
await _vpublishLock.WaitAsync();
try
{
if (_channel == null || _channel.IsClosed)
{
await Connect();
}
var properties = new BasicProperties();
await _channel.BasicPublishAsync(_exchange, _routingKey, properties, body);
}
finally
{
_vpublishLock.Release();
}
}
I hope this fix the issue.