79639952

Date: 2025-05-27 07:07:04
Score: 0.5
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): Can you Add a
  • Low reputation (1):
Posted by: Prishusoft