Description
Expected Behavior
- Triggering an event hub triggered function with cardinality MANY locally via HTTP should pass a list of EventHubEvent to the function.
- Type hints should not influence loading the azure functions.
- The new event hub emulator should work with the event hub trigger.
Actual Behavior
- 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'}]]
- Triggering the function with a request 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.
-
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. Doingdef batch_triggered(events: List[func.EventHubEvent]):
ordef batch_triggered(events: func.EventHubEvent):
is fine, though. -
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
- Set cardinality of event hub triggered function (v2) to many.
- Trigger the function via POST request
Typing Issue
- Type hint event hub triggered function like
def batch_triggered(events: func.EventHubEvent | List[func.EventHubEvent]):
- Start the python workers docker image
Event Hub Emulator Issue
- 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)
- Add healthcheck to event hub, because function app starts way faster than the emulator and fails starting if emulator's not ready
- Make sure the event hub triggered function is not disabled.
- 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. docker compose up
. Function startup will fail, becasue event hub emulator refuses the connection- 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