Skip to content

[Bug] Testing Batched Event Hub Trigger #1524

Open
Azure/azure-functions-python-library
#239
@JonasEichhorn

Description

@JonasEichhorn

Expected Behavior

  1. Triggering an event hub triggered function with cardinality MANY locally via HTTP should pass a list of EventHubEvent to the function.
  2. Type hints should not influence loading the azure functions.
  3. The new event hub emulator should work with the event hub trigger.

Actual Behavior

  1. Triggering an event hub triggered function with cardinality MANY locally via HTTP passes a single EventHubEvent to the function, but wraps the event body in a list.
    • Triggering the function with a request body {'input': {'some': 'awesome', 'event': 'body'}} gives an EventHubEvent with the body [{'some': 'awesome', 'event': 'body'}].
    • Posting multiple events {'input': [{'some': 'awesome', 'event': 'body'}, {'some': 'other', 'event': 'body'}]} gives a nested list [[{'some': 'awesome', 'event': 'body'}, {'some': 'other', 'event': 'body'}]]

I had to write a check to convert single events into a list in order to test my function locally and had to extract all the functionality in a seperate function which is called from my function so I can test it with batches. This solution is not pretty, but fine.

  1. Unfortunately, the type hinting breaks loading the azure function. I dont know why, but proper typing
    def batch_triggered(events: func.EventHubEvent | List[func.EventHubEvent]): prohibits the function from being loaded. It is found, but not loaded. Doing def batch_triggered(events: List[func.EventHubEvent]): or def batch_triggered(events: func.EventHubEvent): is fine, though.

  2. I also tried to use the new event hub emulator instead of triggering the function via HTTP for my tests, but the event hub always refuses the connection. I don't know, if this is an issue of the emulator or the worker. I'm raising this issue here, because the emulator does work with the current version of the python SDK.

Steps to Reproduce

HTTP-Trigger Issue

  1. Set cardinality of event hub triggered function (v2) to many.
  2. Trigger the function via POST request

Typing Issue

  1. Type hint event hub triggered function like def batch_triggered(events: func.EventHubEvent | List[func.EventHubEvent]):
  2. Start the python workers docker image

Event Hub Emulator Issue

  1. Write docker compose running an event hub emulator and the function worker docker image (https://learn.microsoft.com/en-us/azure/event-hubs/test-locally-with-event-hub-emulator?tabs=docker-linux-container#run-the-emulator)
  2. Add healthcheck to event hub, because function app starts way faster than the emulator and fails starting if emulator's not ready
  3. Make sure the event hub triggered function is not disabled.
  4. Set environment variable with emulators connection string (https://learn.microsoft.com/en-us/azure/event-hubs/test-locally-with-event-hub-emulator?tabs=docker-linux-container#interact-with-the-emulator). Pass the name of the environment variable as event hub triggers connection parameter.
  5. docker compose up. Function startup will fail, becasue event hub emulator refuses the connection
  6. Connect to the event hub via python SDK with the same connection string. Sending and receiving events will work.

Relevant code being tried

No response

Relevant log output

No response

requirements.txt file

No response

Where are you facing this problem?

Local - Core Tools

Function app name

No response

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions