I have created a Service Bus Queue in Azure and a deployed Azure Function that is triggered when new data is added to the queue. I also have a DB on azure, where I store the messages and a separate route in an Azure Function get-all-data
that gets all the data from the DB.
However, the function doesn’t get triggered when I add new data to the queue. Also, accessing get-all-data
at {auzrefunction-uri}/api/get-all-data
gives 404
response.
Update: I didn’t really change anything, but get-all-data
HTTP trigger started working. The problem with Service Bus trigger, however, is still the same.
I’m running and deploying the code using VS Code
with Azure extension. I did everything by Microsoft’s documentation.
After running localy, it seems that no functions are found inside my project:
The primary error message:
No job functions found. Try making your job classes and methods public. If you’re using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you’ve called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
More detailed description:
func start --verbose
Found Python version 3.9.5 (py).
%%%%%%
%%%%%%
@ %%%%%% @
@@ %%%%%% @@
@@@ %%%%%%%%%%% @@@
@@ %%%%%%%%%% @@
@@ %%%% @@
@@ %%% @@
@@ %% @@
%%
%
Azure Functions Core Tools
Core Tools Version: 4.0.4704 Commit hash: N/A (64-bit)
Function Runtime Version: 4.7.3.18953
[2023-12-11T00:22:53.287Z] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '319236c6-d816-43f6-a8e4-69d90415285c'
[2023-12-11T00:22:53.295Z] Reading host configuration file 'D:BooksLabsCloudlab3-funchost.json'
[2023-12-11T00:22:53.299Z] Host configuration file read:
[2023-12-11T00:22:53.300Z] {
[2023-12-11T00:22:53.301Z] "version": "2.0",
[2023-12-11T00:22:53.302Z] "logging": {
[2023-12-11T00:22:53.303Z] "applicationInsights": {
[2023-12-11T00:22:53.304Z] "samplingSettings": {
[2023-12-11T00:22:53.305Z] "isEnabled": true,
[2023-12-11T00:22:53.306Z] "excludedTypes": "Request"
[2023-12-11T00:22:53.307Z] }
[2023-12-11T00:22:53.309Z] }
[2023-12-11T00:22:53.310Z] },
[2023-12-11T00:22:53.311Z] "extensionBundle": {
[2023-12-11T00:22:53.312Z] "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2023-12-11T00:22:53.313Z] "version": "[3.*, 4.0.0)"
[2023-12-11T00:22:53.314Z] }
[2023-12-11T00:22:53.315Z] }
[2023-12-11T00:22:53.341Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2023-12-11T00:22:53.344Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2023-12-11T00:22:53.347Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2023-12-11T00:22:53.354Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle
[2023-12-11T00:22:53.358Z] Found a matching extension bundle at C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle3.24.0
[2023-12-11T00:22:53.372Z] Loading functions metadata
[2023-12-11T00:22:53.375Z] Reading functions metadata
[2023-12-11T00:22:53.377Z] Reading functions metadata
[2023-12-11T00:22:53.382Z] 0 functions found
[2023-12-11T00:22:53.385Z] 0 functions found
[2023-12-11T00:22:53.389Z] 0 functions loaded
[2023-12-11T00:22:53.391Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle
[2023-12-11T00:22:53.393Z] Found a matching extension bundle at C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle3.24.0
[2023-12-11T00:22:53.395Z] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[2023-12-11T00:22:53.559Z] Skipping bundle download since it already exists at path C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle3.24.0
[2023-12-11T00:22:53.564Z] Loading extension bundle from C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle3.24.0bin
[2023-12-11T00:22:53.567Z] Script Startup resetting load context with base path: 'C:Usersuser.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle3.24.0bin'.
[2023-12-11T00:22:53.576Z] Reading host configuration file 'D:BooksLabsCloudlab3-funchost.json'
[2023-12-11T00:22:53.578Z] Host configuration file read:
[2023-12-11T00:22:53.579Z] {
[2023-12-11T00:22:53.580Z] "version": "2.0",
[2023-12-11T00:22:53.581Z] "logging": {
[2023-12-11T00:22:53.583Z] "applicationInsights": {
[2023-12-11T00:22:53.584Z] "samplingSettings": {
[2023-12-11T00:22:53.585Z] "isEnabled": true,
[2023-12-11T00:22:53.586Z] "excludedTypes": "Request"
[2023-12-11T00:22:53.587Z] }
[2023-12-11T00:22:53.587Z] }
[2023-12-11T00:22:53.588Z] },
[2023-12-11T00:22:53.589Z] "extensionBundle": {
[2023-12-11T00:22:53.590Z] "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2023-12-11T00:22:53.591Z] "version": "[3.*, 4.0.0)"
[2023-12-11T00:22:53.593Z] }
[2023-12-11T00:22:53.594Z] }
[2023-12-11T00:22:53.853Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2023-12-11T00:22:53.855Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2023-12-11T00:22:53.857Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2023-12-11T00:22:53.954Z] Initializing Warmup Extension.
[2023-12-11T00:22:54.007Z] Initializing Host. OperationId: '319236c6-d816-43f6-a8e4-69d90415285c'.
[2023-12-11T00:22:54.018Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=319236c6-d816-43f6-a8e4-69d90415285c
[2023-12-11T00:22:54.042Z] LoggerFilterOptions
[2023-12-11T00:22:54.043Z] {
[2023-12-11T00:22:54.046Z] "MinLevel": "None",
[2023-12-11T00:22:54.047Z] "Rules": [
[2023-12-11T00:22:54.048Z] {
[2023-12-11T00:22:54.049Z] "ProviderName": null,
[2023-12-11T00:22:54.050Z] "CategoryName": null,
[2023-12-11T00:22:54.051Z] "LogLevel": null,
[2023-12-11T00:22:54.052Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.053Z] },
[2023-12-11T00:22:54.054Z] {
[2023-12-11T00:22:54.055Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-12-11T00:22:54.056Z] "CategoryName": null,
[2023-12-11T00:22:54.057Z] "LogLevel": "None",
[2023-12-11T00:22:54.058Z] "Filter": null
[2023-12-11T00:22:54.059Z] },
[2023-12-11T00:22:54.061Z] {
[2023-12-11T00:22:54.062Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-12-11T00:22:54.063Z] "CategoryName": null,
[2023-12-11T00:22:54.064Z] "LogLevel": null,
[2023-12-11T00:22:54.065Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.066Z] },
[2023-12-11T00:22:54.067Z] {
[2023-12-11T00:22:54.068Z] "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2023-12-11T00:22:54.069Z] "CategoryName": null,
[2023-12-11T00:22:54.071Z] "LogLevel": null,
[2023-12-11T00:22:54.071Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.072Z] }
[2023-12-11T00:22:54.073Z] ]
[2023-12-11T00:22:54.074Z] }
[2023-12-11T00:22:54.076Z] LoggerFilterOptions
[2023-12-11T00:22:54.077Z] {
[2023-12-11T00:22:54.078Z] "MinLevel": "None",
[2023-12-11T00:22:54.080Z] "Rules": [
[2023-12-11T00:22:54.081Z] {
[2023-12-11T00:22:54.082Z] "ProviderName": null,
[2023-12-11T00:22:54.083Z] "CategoryName": null,
[2023-12-11T00:22:54.084Z] "LogLevel": null,
[2023-12-11T00:22:54.085Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.086Z] },
[2023-12-11T00:22:54.087Z] {
[2023-12-11T00:22:54.088Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-12-11T00:22:54.089Z] "CategoryName": null,
[2023-12-11T00:22:54.090Z] "LogLevel": "None",
[2023-12-11T00:22:54.091Z] "Filter": null
[2023-12-11T00:22:54.092Z] },
[2023-12-11T00:22:54.093Z] {
[2023-12-11T00:22:54.095Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-12-11T00:22:54.096Z] "CategoryName": null,
[2023-12-11T00:22:54.097Z] "LogLevel": null,
[2023-12-11T00:22:54.098Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.099Z] },
[2023-12-11T00:22:54.100Z] {
[2023-12-11T00:22:54.101Z] "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2023-12-11T00:22:54.102Z] "CategoryName": null,
[2023-12-11T00:22:54.103Z] "LogLevel": null,
[2023-12-11T00:22:54.104Z] "Filter": "<AddFilter>b__0"
[2023-12-11T00:22:54.105Z] }
[2023-12-11T00:22:54.106Z] ]
[2023-12-11T00:22:54.107Z] }
[2023-12-11T00:22:54.108Z] ConcurrencyOptions
[2023-12-11T00:22:54.109Z] {
[2023-12-11T00:22:54.110Z] "DynamicConcurrencyEnabled": false,
[2023-12-11T00:22:54.112Z] "MaximumFunctionConcurrency": 500,
[2023-12-11T00:22:54.113Z] "CPUThreshold": 0.8,
[2023-12-11T00:22:54.114Z] "SnapshotPersistenceEnabled": true
[2023-12-11T00:22:54.115Z] }
[2023-12-11T00:22:54.116Z] FunctionResultAggregatorOptions
[2023-12-11T00:22:54.117Z] {
[2023-12-11T00:22:54.118Z] "BatchSize": 1000,
[2023-12-11T00:22:54.119Z] "FlushTimeout": "00:00:30",
[2023-12-11T00:22:54.120Z] "IsEnabled": true
[2023-12-11T00:22:54.121Z] }
[2023-12-11T00:22:54.122Z] SingletonOptions
[2023-12-11T00:22:54.123Z] {
[2023-12-11T00:22:54.124Z] "LockPeriod": "00:00:15",
[2023-12-11T00:22:54.125Z] "ListenerLockPeriod": "00:00:15",
[2023-12-11T00:22:54.126Z] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[2023-12-11T00:22:54.127Z] "LockAcquisitionPollingInterval": "00:00:05",
[2023-12-11T00:22:54.128Z] "ListenerLockRecoveryPollingInterval": "00:01:00"
[2023-12-11T00:22:54.129Z] }
[2023-12-11T00:22:54.132Z] Starting JobHost
[2023-12-11T00:22:54.136Z] Starting Host (HostId=desktopjcuvdfa-1433332689, InstanceId=c16617d5-921b-4758-a9c6-dca27fe2e074, Version=4.7.3.18953, ProcessId=9472, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[2023-12-11T00:22:54.141Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[2023-12-11T00:22:54.143Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[2023-12-11T00:22:54.145Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[2023-12-11T00:22:54.158Z] Loading functions metadata
[2023-12-11T00:22:54.160Z] Reading functions metadata
[2023-12-11T00:22:54.161Z] Reading functions metadata
[2023-12-11T00:22:54.163Z] 0 functions found
[2023-12-11T00:22:54.164Z] 0 functions found
[2023-12-11T00:22:54.172Z] 0 functions loaded
[2023-12-11T00:22:54.192Z] Generating 0 job function(s)
[2023-12-11T00:22:54.212Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[2023-12-11T00:22:54.221Z] HttpOptions
[2023-12-11T00:22:54.222Z] Initializing function HTTP routes
[2023-12-11T00:22:54.223Z] {
[2023-12-11T00:22:54.224Z] No HTTP routes mapped
[2023-12-11T00:22:54.226Z]
[2023-12-11T00:22:54.225Z] "DynamicThrottlesEnabled": false,
[2023-12-11T00:22:54.228Z] "EnableChunkedRequestBinding": false,
[2023-12-11T00:22:54.229Z] "MaxConcurrentRequests": -1,
[2023-12-11T00:22:54.230Z] "MaxOutstandingRequests": -1,
[2023-12-11T00:22:54.231Z] "RoutePrefix": "api"
[2023-12-11T00:22:54.233Z] }
[2023-12-11T00:22:54.235Z] Host initialized (87ms)
[2023-12-11T00:22:54.238Z] Host started (98ms)
[2023-12-11T00:22:54.239Z] Job host started
[2023-12-11T00:22:59.063Z] Host lock lease acquired by instance ID '0000000000000000000000003014F25D'.
Here’s my function at function_app.py
:
import azure.functions as func
import mysql.connector
import logging
import json
from datetime import datetime
app = func.FunctionApp()
@app.function_name(name="my-function")
@app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="my-sb-queue",
connection="sb://name.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=someRandomKeyLetters=")
def servicebus_queue_trigger(azservicebus: func.ServiceBusMessage):
logging.info('Python ServiceBus Queue trigger processed a message: %s',
azservicebus.get_body().decode('utf-8'))
try:
message_body = azservicebus.get_body().decode('utf-8')
conn = mysql.connector.connect(user="user", password="pwd", host="db-name.mysql.database.azure.com", port=3306, database="sensors")
cursor = conn.cursor()
# Extract data from the message
sensor_type = message_body['sensor_type']
location = message_body['location']
date = message_body['date']
property_value = message_body['property']
# Convert date string to datetime object
date_obj = datetime.strptime(date, '%Y-%m-%d')
# Insert data into the database
insert_query = (
"INSERT INTO sensor_data (sensor_type, location, date, property) VALUES (%s, %s, %s, %s)"
)
insert_values = (sensor_type, location, date_obj, property_value)
cursor.execute(insert_query, insert_values)
conn.commit()
# Close the database connection
cursor.close()
conn.close()
except Exception as e:
print(f"An error occurred: {str(e)}")
@app.route(route="get-all-data", auth_level=func.AuthLevel.ANONYMOUS)
def get_all_data(req: func.HttpRequest) -> func.HttpResponse:
try:
conn = mysql.connector.connect(user="user", password="pwd", host="db-name.mysql.database.azure.com", port=3306, database="sensors")
cursor = conn.cursor()
# Select all data from the database
query = "SELECT * FROM sensor_data"
cursor.execute(query)
rows = cursor.fetchall()
# Close the database connection
cursor.close()
conn.close()
# Convert database rows to a list of dictionaries
data = []
for row in rows:
entry = {
'id': row[0],
'sensor_type': row[1],
'location': row[2],
'date': row[3].strftime("%Y-%m-%d"),
'property': row[4]
}
data.append(entry)
# Return the data as an HTTP response
return func.HttpResponse(json.dumps(data), mimetype="application/json", status_code=200)
except Exception as e:
return func.HttpResponse(f"An error occurred: {str(e)}", status_code=500)
My host.json
:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
}
}
My local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
2
Answers
Actually, I spent around
15
hours trying different things, yet it started working for absolutely no reason after trying to deploy and redeploy this very code a few times in a row.Upgrade the
Azure function core tools
to latest version. You can download it from here.I have
Azure function core tools
version4.0.5455
and used"version": "[4.*, 5.0.0)"
inhost.json
.I have used your code and made changes in
# Extract data from the message
, which worked for me.function_app.py
:local.settings.json
:host.json
:OUTPUT
:sample message
:http_trigger output
: