diff --git a/projects/RabbitMQ.Client/Impl/ChannelBase.cs b/projects/RabbitMQ.Client/Impl/ChannelBase.cs index eb12111a5..6ba9ed60c 100644 --- a/projects/RabbitMQ.Client/Impl/ChannelBase.cs +++ b/projects/RabbitMQ.Client/Impl/ChannelBase.cs @@ -1023,6 +1023,9 @@ await _confirmSemaphore.WaitAsync(cancellationToken) _nextPublishSeqNo++; } + await EnforceFlowControlAsync(cancellationToken) + .ConfigureAwait(false); + var cmd = new BasicPublish(exchange, routingKey, mandatory, default); using Activity? sendActivity = RabbitMQActivitySource.PublisherHasListeners @@ -1032,15 +1035,11 @@ await _confirmSemaphore.WaitAsync(cancellationToken) BasicProperties? props = PopulateBasicPropertiesHeaders(basicProperties, sendActivity, publishSequenceNumber); if (props is null) { - await EnforceFlowControlAsync(cancellationToken) - .ConfigureAwait(false); await ModelSendAsync(in cmd, in basicProperties, body, cancellationToken) .ConfigureAwait(false); } else { - await EnforceFlowControlAsync(cancellationToken) - .ConfigureAwait(false); await ModelSendAsync(in cmd, in props, body, cancellationToken) .ConfigureAwait(false); } @@ -1105,7 +1104,11 @@ await _confirmSemaphore.WaitAsync(cancellationToken) _nextPublishSeqNo++; } + await EnforceFlowControlAsync(cancellationToken) + .ConfigureAwait(false); + var cmd = new BasicPublishMemory(exchange.Bytes, routingKey.Bytes, mandatory, default); + using Activity? sendActivity = RabbitMQActivitySource.PublisherHasListeners ? RabbitMQActivitySource.Send(routingKey.Value, exchange.Value, body.Length) : default; @@ -1113,15 +1116,11 @@ await _confirmSemaphore.WaitAsync(cancellationToken) BasicProperties? props = PopulateBasicPropertiesHeaders(basicProperties, sendActivity, publishSequenceNumber); if (props is null) { - await EnforceFlowControlAsync(cancellationToken) - .ConfigureAwait(false); await ModelSendAsync(in cmd, in basicProperties, body, cancellationToken) .ConfigureAwait(false); } else { - await EnforceFlowControlAsync(cancellationToken) - .ConfigureAwait(false); await ModelSendAsync(in cmd, in props, body, cancellationToken) .ConfigureAwait(false); }