I am writing an EventHub publisher (Console app) and an C# Azure Function that will work as a consumer. when I run the client, I can see the Function getting triggered, but it receives 0 bytes ineventData.Body. Can anyone help me here? I have seen some other similar questions about empty events received in Az Function. this is differnt, because trigger is fired everytime I send a batch of 10, but somehow the data is eaten up
My function code is
[FunctionName("EventHubTrigger1")]
public static async Task Run([EventHubTrigger("confighub", Connection = "EventHubName")] EventData[] events, ILogger log)
{
var exceptions = new List<Exception>();
foreach (EventData eventData in events)
{
try
{
//eventData.Body is System.ReadOnlyMemory<Byte>[0] instead of what the sender is sending
string messageBody = Encoding.UTF8.GetString(eventData.Body.ToArray());
log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
await Task.Yield();
}
catch (Exception e)
{
exceptions.Add(e);
}
}
if (exceptions.Count > 1)
throw new AggregateException(exceptions);
if (exceptions.Count == 1)
throw exceptions.Single();
}
the publisher is also simple and during debugging I can see that the EventData.Body is System.ReadOnlyMemory<Byte>[456]
private async Task SendToHub(IEnumerable<IDomain> users)
{
await using (var producerClient = new EventHubProducerClient(_eventHubConnectionString, _eventHubName))
{
try
{
CreateBatchOptions options = new CreateBatchOptions();
options.PartitionKey = "user";
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync(options);
foreach (var user in users)
{
var json = JsonSerializer.Serialize(user);
eventBatch.TryAdd(new Azure.Messaging.EventHubs.EventData(Encoding.UTF8.GetBytes(json)));
}
//During Debugging I can see that the Body is 456 bytes
await producerClient.SendAsync(eventBatch);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}