Skip to content

Error with v4 EventHub trigger and cardinality many #187

@rvk86

Description

@rvk86

I'm upgrading my EventHub trigger to the v4 programming model. When I run the trigger locally and publishing a message the code works fine with cardinality: "one", but when I switch to cardinality: "many" I'm receiving the following error:

[2023-11-03T09:33:04.431Z] Executed 'Functions.location-updates' (Failed, Id=eac578f2-f16e-470b-8474-601a02d0e0b8, Duration=59ms)
[2023-11-03T09:33:04.432Z] System.Private.CoreLib: Exception while executing function: Functions.location-updates. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'eventHubTrigger1'. Microsoft.Azure.WebJobs.Host: Binding parameters to complex objects (such as 'Object') uses Json.NET serialization. 
[2023-11-03T09:33:04.432Z] 1. Bind the parameter type as 'string' instead of 'Object' to get the raw values and avoid JSON deserialization, or
[2023-11-03T09:33:04.432Z] 2. Change the queue payload to be valid json. The JSON parser failed: Unexpected character encountered while parsing value: . Path '', line 0, position 0.

Repro steps

  1. Run the below code locally with func start
  2. Publish a message to the EventHub the trigger is listening to
  3. Observe the error being thrown
import { app } from "@azure/functions";

const eventHubTrigger = async function (
    eventHubMessages: any
): Promise<void> {
    console.log(eventHubMessages);
};

app.eventHub("location-updates", {
    eventHubName: process.env.EVENT_HUB_NAME,
    connection: "EVENT_HUB_CONNECTION",
    handler: eventHubTrigger,
    cardinality: "many", // if this is set to "one" the trigger works fine
});

Expected behavior

I'd expect the handler function to run with an array of strings as the first argument.

Actual behavior

The emulator throws the error as shown above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions