Skip to content

[BUG] EventHub .NET Sample. Wrong instructions in README #17263

Closed

Description

Following https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/samples/Sample01_HelloWorld.md I found missing instructions:

Expected behavior
I can follow and complete the tutorial

Actual behavior (include Exception or Stack Trace)
The sample code does not compile

I fixed by following the next steps.

  1. Add main NuGet dotnet add package Azure.Messaging.EventHubs
  2. Update AMQP to workaround: Possible incompatibility with .NET 5.0 azure-amqp#165
  3. Add dotnet add package System.Memory.Data to be able to use BinaryData
  4. Update code to avoid using partitionEvent.Data.EventBody

I update the code from

await foreach (PartitionEvent partitionEvent in consumer.ReadEventsAsync(cancellationSource.Token))
{
    eventDataRead.Add(partitionEvent.Data.EventBody.ToString());
    if (eventDataRead.Count >= maximumEvents)
    {
        break;
    }
}

to:

await foreach (PartitionEvent partitionEvent in consumer.ReadEventsAsync(cancellationSource.Token))
{
    var data = BinaryData.FromBytes(partitionEvent.Data.Body);
    eventDataRead.Add(data.ToString());
                    
    if (eventDataRead.Count >= maximumEvents)
    {
        break;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.DocsEvent Hubs

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions