[Python] Why is my azure python V2 function app event hub trigger not triggering?

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    We are trying to build a simple function app (see below) but the events written into the "trigger" event hub never kick off the function. The goal is to utilize a "premium" V2 python function app running on an "Elastic Service App" that utilizes both "event_hub_message_trigger" and "event_hub_output" to forward events from an event hub on one tenant (TENANT_ONE_EH below) to an event hub on another (TENANT_TWO_EH below). All components are private (no public network access) with private endpoints configured. Here is the code:

    import datetime
    import json
    import azure.functions as func
    import logging

    app = func.FunctionApp()

    @app.function_name(name="event_hub_forwarder")
    @app.event_hub_output(arg_name="outputEvent", event_hub_name="tenant_two_eventhub", connection="TENANT_TWO_EH")
    @app.event_hub_message_trigger(arg_name="inputEvent", consumer_group="forwarder", event_hub_name="tenant_one_eventhub", connection="TENANT_ONE_EH")
    def eventhub_function(inputEvent: func.EventHubEvent, outputEvent: func.Out[str]):
    logging.info('Python EventHub trigger processed an event: %s with enqueued time: %s', inputEvent.get_body().decode('utf-8'), str(inputEvent.enqueued_time))
    input_dict = json.loads(inputEvent.get_body())
    now = datetime.datetime.now()
    input_dict['time_processed'] = str(now)

    outputEvent.set(json.dumps(input_dict))


    The function runs as expected locally using a eventhub emulator and azurite storage emulator in VS code. Using a VM (via bastion) I am able to upload the function to the cloud via the CLI (cannot use the portal because no public network access and the VM doesn't have a desktop). On the VM in the cloud I am able to:

    • Trigger the function via curl (using: this) - this works as expected, the json is ingested, the process field is appended, and the event is pushed to the second tenants event hub.
    • Use a python script (not the azure function just a simple script) to write and read from both event hubs (using the same connection string utilized by the function app. This is also how I test the functionality (python write to EH1 -> function app triggers and writes to EH2 -> python read from EH2)

    I have been able to find a few logs (both from CLI log stream and from SSHing into the container running the function via "az webapp create-remote-connection") that have given me a few hints:

    1. I believe the trigger is running regularly and is connecting to the first tenants eventhub (TENANT_ONE_EH above) because I see a reoccurring log:

    2025-02-13T14:03:34.042 [Information] Querying partition information for 10 partitions. 2025-02-13T14:03:34.262 [Information] Target worker count for function 'Host.Functions.event_hub_forwarder' is '0' (EventHubName='tenant_one_eventhub', EventCount ='0', Concurrency='10', PartitionCount='10').
    ​

    The partition count changed appropriately when I switched to a different event hub with a different partition count.

    1. There is a repeating 403 error from Microsoft.Azure.WebJobs.Host.Scale.ScaleManager.GetTargetScalersResultAsync (here) but since this is an EventHub trigger my understanding is that shouldnt matter and may be related to this.

    The "EventCount" is always 0 (#1 above) so my gut tells me the trigger isn't seeing any of the actual events so it never scales up to process anything (thus why the target worker count also stays at 0). I have ensured the ConsumerGroup exists ("forwarder" in the code above) and can read from it just fine with the python code (as mentioned above).

    Any ideas on threads to pull on this one? I am happy to provide any additional information/clarifications necessary.

    Continue reading...

Compartilhe esta Página