Skip to content

[QUESTION] EventBatch doesn't clear after being sent #16030

@ArmandoLacerda

Description

@ArmandoLacerda

Describe the bug
When sending multiple messages through the eventBatch helper, it doesn't clear out after the batch is submitted. I have a 5MB payload to send to the hub. I break the payload in many smaller messages and loop through them, adding them up to the eventBatch until it gets close to 1MB. Then I invoke producerClient.SendAsync() to submit the batch and resume the loop for the next collection of messages. eventBatch doesn't zero out and the loop tries to resubmit the same batch. The eventBatch.SizeInBytes still shows the already submitted payload.

Expected behavior
After invoking producerClient.SendAsync(eventBatch) I expect to get a clean batch to start filling up with new messages.

Actual behavior (include Exception or Stack Trace)
The eventBatch does not clear out. It is of no use in a loop to send a payload larger than 1MB.

To Reproduce
A slightly modified version of the sample official sample:

`
public static void trySendingMultipleBatches()
{
{
// Create a producer client that you can use to send events to an event hub
await using (var producerClient = new EventHubProducerClient(connectionString, eventHubName))
{
// Create a batch of events
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();

        // Try 3 batches 
        for (int i = 0; i < 3; i++)
        {

            while (eventBatch.SizeInBytes < 800000)
            {
                // Add events to the batch. An event is a represented by a collection of bytes and metadata. 
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("First event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Second event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Third event")));
            }
            // Use the producer client to send the batch of events to the event hub
            await producerClient.SendAsync(eventBatch);
            Console.WriteLine("A batch of about 1MB has been published.");
        }
    }
}

}

`

Environment:

  • Azure.Messaging.EventHubs 5.2.0

  • Hosting platform or OS and .NET runtime version (dotnet --info)
    .NET Core SDK (reflecting any global.json):
    Version: 3.1.300
    Commit: b2475c1295

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.300\

Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6

.NET Core SDKs installed:
3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • Visual Studio Code
    Version: 1.50.1 (user setup)
    Commit: d2e414d9e4239a252d1ab117bd7067f125afd80a
    Date: 2020-10-13T15:06:15.712Z
    Electron: 9.2.1
    Chrome: 83.0.4103.122
    Node.js: 12.14.1
    V8: 8.3.110.13-electron.0
    OS: Windows_NT x64 10.0.18363

Metadata

Metadata

Assignees

Labels

ClientThis issue is related to a non-management packageEvent Hubscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions