Skip to content

use cached empty BasicProperties when null #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions projects/RabbitMQ.Client/client/impl/BasicPublishBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ internal BasicPublishBatch (ModelBase model)

public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body)
{
IBasicProperties bp = basicProperties ?? _model.CreateBasicProperties();
var method = new BasicPublish
{
_exchange = exchange,
_routingKey = routingKey,
_mandatory = mandatory
};

_commands.Add(new Command(method, (ContentHeaderBase)bp, body, false));
_commands.Add(new Command(method, (ContentHeaderBase)(basicProperties ?? _model._emptyBasicProperties), body, false));
}

public void Publish()
Expand Down
5 changes: 3 additions & 2 deletions projects/RabbitMQ.Client/client/impl/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ abstract class ModelBase : IFullModel, IRecoverable
///<summary>Only used to kick-start a connection open
///sequence. See <see cref="Connection.Open"/> </summary>
public BlockingCell<ConnectionStartDetails> m_connectionStartCell = null;
internal readonly IBasicProperties _emptyBasicProperties;

private readonly Dictionary<string, IBasicConsumer> _consumers = new Dictionary<string, IBasicConsumer>();

Expand All @@ -72,7 +73,6 @@ abstract class ModelBase : IFullModel, IRecoverable
private readonly object _confirmLock = new object();
private readonly LinkedList<ulong> _pendingDeliveryTags = new LinkedList<ulong>();
private readonly CountdownEvent _deliveryTagsCountdown = new CountdownEvent(0);

private EventHandler<ShutdownEventArgs> _modelShutdown;

private bool _onlyAcksReceived = true;
Expand All @@ -93,6 +93,7 @@ public ModelBase(ISession session, ConsumerWorkService workService)
ConsumerDispatcher = new ConcurrentConsumerDispatcher(this, workService);
}

_emptyBasicProperties = CreateBasicProperties();
Initialise(session);
}

Expand Down Expand Up @@ -1111,7 +1112,7 @@ public void BasicPublish(string exchange,

if (basicProperties == null)
{
basicProperties = CreateBasicProperties();
basicProperties = _emptyBasicProperties;
}

if (NextPublishSeqNo > 0)
Expand Down