Skip to content

Commit 108fc97

Browse files
committed
Enable MessagingEventSource logging to comply with the rest of SendAsync methods
1 parent 97a1783 commit 108fc97

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ public bool TryAdd(Message message)
6363

6464
}
6565

66+
/// <summary>
67+
/// Number of messages in batch.
68+
/// </summary>
69+
public int Length => datas.Count;
70+
6671
private long Size => result.SerializedMessageSize;
6772

73+
6874
/// <summary>
69-
/// Convert batch to AMQP message
75+
/// Convert batch to AMQP message.
7076
/// </summary>
7177
/// <returns></returns>
7278
public AmqpMessage ToAmqpMessage()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public async Task SendAsync(Batch batch)
277277
{
278278
this.ThrowIfClosed();
279279

280-
// MessagingEventSource.Log.MessageSendStart(this.ClientId, count);
280+
MessagingEventSource.Log.MessageSendStart(this.ClientId, batch.Length);
281281

282282
// var isDiagnosticSourceEnabled = ServiceBusDiagnosticSource.IsEnabled();
283283
// var activity = isDiagnosticSourceEnabled ? this.diagnosticSource.SendStart(messageList) : null;

test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ namespace Microsoft.Azure.ServiceBus.Core
483483
public class Batch : System.IDisposable
484484
{
485485
public Batch(long maximumBatchSize) { }
486+
public int Length { get; }
486487
public void Dispose() { }
487488
public Microsoft.Azure.Amqp.AmqpMessage ToAmqpMessage() { }
488489
public bool TryAdd(Microsoft.Azure.ServiceBus.Message message) { }

test/Microsoft.Azure.ServiceBus.UnitTests/Primitives/BatchTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,21 @@ public void Should_throw_when_trying_to_add_an_already_received_message_to_batch
4141
Assert.Throws<ArgumentException>(() => batch.TryAdd(message));
4242
}
4343
}
44+
45+
[Theory]
46+
[InlineData(1)]
47+
[InlineData(3)]
48+
public void Should_report_how_many_messages_are_in_batch(int numberOfMessages)
49+
{
50+
using (var batch = new Batch(100))
51+
{
52+
for (var i = 0; i < numberOfMessages; i++)
53+
{
54+
batch.TryAdd(new Message());
55+
}
56+
57+
Assert.Equal(numberOfMessages, batch.Length);
58+
}
59+
}
4460
}
4561
}

0 commit comments

Comments
 (0)