Iain Brown
Iain Brown

Reputation: 1171

Get EventHub metadata when using an isolated process Azure Function

I'm looking at migrating an existing in process Azure Function to isolated process so that I can move to .net7. The in process (.net6) version of the function looks like this:

[FunctionName("Function1")]
public async Task Run([EventHubTrigger("%eventhubname%", Connection = "ehconnection")] EventData[] events)
{
    foreach (var event in events)
    {
        // query the metadata and then process the event
    }
}

And this works fine with in process, but if I use this with isolated process SDK then I get the following exception

[2022-11-16T11:08:03.989Z] Executed 'Functions.Function1' (Failed, Id=<id>, Duration=58ms)
[2022-11-16T11:08:03.990Z] System.Private.CoreLib: Exception while executing function: Functions.Function1. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'events'. Microsoft.Azure.WebJobs.Host: Binding parameters to complex objects (such as 'Object') uses Json.NET serialization.
1. Bind the parameter type as 'string' instead of 'Object' to get the raw values and avoid JSON deserialization, or
2. Change the queue payload to be valid json. The JSON parser failed: Unexpected character encountered while parsing value: F. Path '', line 0, position 0.

I can use string [] as a parameter to the function instead of EventData[] and that works, but then I don't have access to the metadata (e.g. the enqueue time) of the event which I want for various reasons.

Is there any way to get hold of the metadata when using an isolated process?

Upvotes: 0

Views: 847

Answers (1)

Iain Brown
Iain Brown

Reputation: 1171

Worked it out by finding the samples here. The metadata can be retrieved using a function with the following signature.

 [Function("FunctionName")]
 public static void UsingParameters([EventHubTrigger("src-parameters", Connection = "EventHubConnectionAppSetting")] 
     string[] messages,
     DateTime[] enqueuedTimeUtcArray,
     long[] sequenceNumberArray,
     string[] offsetArray,
     Dictionary<string, JsonElement>[] propertiesArray,
     Dictionary<string, JsonElement>[] systemPropertiesArray)
{
}

Upvotes: 2

Related Questions