[Python] Azure Functions: get Service Bus topic_name and subscription_name from environment or...

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    When writing an Azure Function for handling Service Bus events in Python, one decorates the handler function with @service_bus_topic_trigger (docs):

    @service_bus_topic_trigger(arg_name="msg",
    topic_name="TOPIC_NAME",
    subscription_name="SUBSCRIPTION_NAME",
    connection="CONNECTION_SETTING")
    def handler(msg):
    ... body goes here ...


    The connection argument will typically hold a secret, and documentation encourages developers to pass an Argument Setting key rather than an explicit value. However, all the documentation examples for topic_name and subscription_name pass the values of the topic/subscription as explicit strings, not references to settings.

    The question is, does Azure support looking up topic/subscription name from application settings at runtime? Of course, we could query os.environ directly, but since the method and its decorator must be at module scope, this would require doing IO on module load, which is an anti-pattern.

    Continue reading...

Compartilhe esta Página