Skip to content

Commit 700cd57

Browse files
committed
Ensure properties from the first message needed for a batch are included in the safe size calculation.
1 parent 36f7e88 commit 700cd57

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/Microsoft.Azure.ServiceBus/Core/MessageBatch.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class MessageBatch : IDisposable
2020
private AmqpMessage firstMessage;
2121
private readonly List<Data> datas;
2222
private AmqpMessage result;
23-
private (string messageId, string sessionId, string partitionKey, string viaPartitionKey) originalMessageData;
2423

2524
/// <summary>
2625
/// Construct a new batch with a maximum batch size and outgoing plugins callback.
@@ -56,8 +55,27 @@ public async Task<bool> TryAdd(Message message)
5655

5756
if (firstMessage == null)
5857
{
59-
originalMessageData = (processedMessage.MessageId, processedMessage.SessionId, processedMessage.PartitionKey, processedMessage.ViaPartitionKey);
6058
firstMessage = amqpMessage;
59+
60+
if (processedMessage.MessageId != null)
61+
{
62+
result.Properties.MessageId = processedMessage.MessageId;
63+
}
64+
65+
if (processedMessage.SessionId != null)
66+
{
67+
result.Properties.GroupId = processedMessage.SessionId;
68+
}
69+
70+
if (processedMessage.PartitionKey != null)
71+
{
72+
result.MessageAnnotations.Map[AmqpMessageConverter.PartitionKeyName] = processedMessage.PartitionKey;
73+
}
74+
75+
if (processedMessage.ViaPartitionKey != null)
76+
{
77+
result.MessageAnnotations.Map[AmqpMessageConverter.ViaPartitionKeyName] = processedMessage.ViaPartitionKey;
78+
}
6179
}
6280

6381
var data = AmqpMessageConverter.ToData(amqpMessage);
@@ -95,26 +113,6 @@ internal AmqpMessage ToAmqpMessage()
95113
return firstMessage;
96114
}
97115

98-
if (originalMessageData.messageId != null)
99-
{
100-
result.Properties.MessageId = originalMessageData.messageId;
101-
}
102-
103-
if (originalMessageData.sessionId != null)
104-
{
105-
result.Properties.GroupId = originalMessageData.sessionId;
106-
}
107-
108-
if (originalMessageData.partitionKey != null)
109-
{
110-
result.MessageAnnotations.Map[AmqpMessageConverter.PartitionKeyName] = originalMessageData.partitionKey;
111-
}
112-
113-
if (originalMessageData.viaPartitionKey != null)
114-
{
115-
result.MessageAnnotations.Map[AmqpMessageConverter.ViaPartitionKeyName] = originalMessageData.viaPartitionKey;
116-
}
117-
118116
result.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat;
119117
result.Batchable = true;
120118
return result;

0 commit comments

Comments
 (0)