Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventHubTrigger throws error when handling IoTHub messages #9749

Closed
ladeak opened this issue Dec 26, 2023 · 1 comment
Closed

EventHubTrigger throws error when handling IoTHub messages #9749

ladeak opened this issue Dec 26, 2023 · 1 comment

Comments

@ladeak
Copy link

ladeak commented Dec 26, 2023

[EventHubTrigger] throws error when handling IoTHub messages

Repro steps

Migrating an in-process C# Azure Function to isolated worker process and to .NET 8.

Following documentation: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-iot-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-csharp

and

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-csharp

Expected behavior

Receive the message.

Actual behavior

Regardless I use batched non-batched, string, byte[], or Azure.Messaging.EventHubs.EventData I get the following errors on the output.

[2023-12-26T20:08:48.119Z] System.Private.CoreLib: Exception while executing function: Functions.Name. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'message'. Azure.Messaging.EventHubs: The event body cannot be retrieved using the EventBody property of EventData.  A body of type Value can be accessed using the GetRawAmqpMessage method of EventData and inspecting the underlying AMQP message.
[2023-12-26T20:08:58.136Z] Executing 'Functions.Name' (Reason='(null)', Id=3eff2c45-e91e-4f6c-b2cf-d426de31f17b)
[2023-12-26T20:08:58.138Z] Trigger Details: PartionId: 1, Offset: 22496, EnqueueTimeUtc: 2023-12-26T19:59:24.9080000+00:00, SequenceNumber: 31, Count: 1
[2023-12-26T20:08:58.140Z] Executed 'Functions.Name' (Failed, Id=3eff2c45-e91e-4f6c-b2cf-d426de31f17b, Duration=3ms)
[2023-12-26T20:08:58.142Z] System.Private.CoreLib: Exception while executing function: Functions.Name. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'message'. Azure.Messaging.EventHubs: The event body cannot be retrieved using the EventBody property of EventData.  A body of type Value can be accessed using the GetRawAmqpMessage method of EventData and inspecting the underlying AMQP message.

The message is sent by an IotDevice, which has not changed behavior.

Related information

Dependencies:

    <PackageReference Include="Microsoft.Azure.Devices" Version="1.39.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.EventHubs" Version="6.0.1" />

Azure Functions version:

    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    [Function("Name")]
    [FixedDelayRetry(5, "00:00:10")]
    public async Task Run([EventHubTrigger("iothub-ehub-...", Connection = "eventHubConnectionString", IsBatched = false)] Azure.Messaging.EventHubs.EventData message, FunctionContext context)
    {
        _logger.LogInformation($"C# IoT Hub trigger function processed a message");
    }

I am testing on my dev machine.

Note, that previously with the in-proc binding using <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="6.0.2" /> the function was working.

@ladeak
Copy link
Author

ladeak commented Dec 26, 2023

I resolved the issue by sending AmqpData instead of AmqpValue after finding: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Azure.Messaging.EventHubs/src/Amqp/AmqpAnnotatedMessageExtensions.cs#L151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant