From d7e618d104b3b0d8aa8807ea6403085fc3d4e1d2 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 8 Oct 2024 07:52:54 -0700 Subject: [PATCH] Simplify code. --- projects/RabbitMQ.Client/Impl/ChannelBase.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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); }