pythonazureazure-functionsazureservicebus

Azure Functions Service Bus Triggered not working


This is my Python code for Azure functions.

import logging
import json

app = func.FunctionApp()
logging.info("Function starting...")
print("Function starting...")

import os 

def process_message(message: func.ServiceBusMessage):
    try:
        logging.info("Processing service bus message")
        # Join all chunks and decode to string
        body_bytes = message.get_body()
        body_str = body_bytes.decode('utf-8')
        try:
            result = json.loads(body_str)
        except json.JSONDecodeError:
            result = body_str
        logging.info(f"Processed service bus message: {result}")
        return result

    except Exception as e:
        print(f"Error processing message: {str(e)}  ")

@app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="new-user", connection="ServiceBusConnectionString") 
def new_user_job_recommendation(azservicebus: func.ServiceBusMessage):
    logging.info("Function called...")
    user_id = process_message(message=azservicebus)
    logging.info(f"Received message from queue: {user_id}")

    logging.info("Function completed.")

This code works locally and is able to fetch messages from service bus.

But after deploying it does not pick messages from service bus (i am using same connection string).

This is my app settings. App Settings

Also here you can see it has linked with App Settings variable Trigger Details


Solution

  • Error while loading Ask questions and use troubleshooting tools to investigate these errors.Diagnose and solve problems

    • Encountered an error (InternalServerError) from host runtime

    To fix the error, add the below to the Azure Function App > Environment variables > App Settings and Restart the Function again.

    AzureWebJobsStorage : <StorageConnectionString>
    

    I sent the below message in the Service Bus queue.

    enter image description here

    Invocations :

    I successfully ran the Service Bus Queue trigger function and retrieved the messages from service bus queue.

    enter image description here

    Reference : https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#:~:text=key%20storage.-,AzureWebJobsStorage,-Specifies%20the%20connection