Skip to content

Commit a77a19f

Browse files
Merge pull request #887 from bollhals/cache.BasicProperties
use cached empty BasicProperties when null (cherry picked from commit 772dc4d)
1 parent 486d6bb commit a77a19f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

projects/RabbitMQ.Client/client/impl/BasicPublishBatch.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ internal BasicPublishBatch (ModelBase model)
5757

5858
public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body)
5959
{
60-
IBasicProperties bp = basicProperties ?? _model.CreateBasicProperties();
6160
var method = new BasicPublish
6261
{
6362
_exchange = exchange,
6463
_routingKey = routingKey,
6564
_mandatory = mandatory
6665
};
6766

68-
_commands.Add(new Command(method, (ContentHeaderBase)bp, body, false));
67+
_commands.Add(new Command(method, (ContentHeaderBase)(basicProperties ?? _model._emptyBasicProperties), body, false));
6968
}
7069

7170
public void Publish()

projects/RabbitMQ.Client/client/impl/ModelBase.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ abstract class ModelBase : IFullModel, IRecoverable
5858
///<summary>Only used to kick-start a connection open
5959
///sequence. See <see cref="Connection.Open"/> </summary>
6060
public BlockingCell<ConnectionStartDetails> m_connectionStartCell = null;
61+
internal readonly IBasicProperties _emptyBasicProperties;
6162

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

@@ -72,7 +73,6 @@ abstract class ModelBase : IFullModel, IRecoverable
7273
private readonly object _confirmLock = new object();
7374
private readonly LinkedList<ulong> _pendingDeliveryTags = new LinkedList<ulong>();
7475
private readonly CountdownEvent _deliveryTagsCountdown = new CountdownEvent(0);
75-
7676
private EventHandler<ShutdownEventArgs> _modelShutdown;
7777

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

96+
_emptyBasicProperties = CreateBasicProperties();
9697
Initialise(session);
9798
}
9899

@@ -1111,7 +1112,7 @@ public void BasicPublish(string exchange,
11111112

11121113
if (basicProperties == null)
11131114
{
1114-
basicProperties = CreateBasicProperties();
1115+
basicProperties = _emptyBasicProperties;
11151116
}
11161117

11171118
if (NextPublishSeqNo > 0)

0 commit comments

Comments
 (0)