Код: Выделить всё
import logging
import azure.functions as func
from azure.storage.queue import QueueServiceClient
# Initialize queue client
queue_service = QueueServiceClient.from_connection_string("{YOUR_CONNECTION_STRING}")
queue_client = queue_service.get_queue_client("{YOUR_QUEUE_NAME}")
@app.route(route="{YOUR_FUNCTION_ROUTE}", auth_level=func.AuthLevel.ANONYMOUS)
def GetUrlsFunction(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# Example URL to be added to the queue
example_url = "{YOUR_URL}"
# Send message to the queue
queue_client.send_message(example_url)
logging.info(f"Message added to the queue: {example_url}")
return func.HttpResponse(
"URLs have been added to the queue successfully.",
status_code=200
)
Код: Выделить всё
@app.queue_trigger(arg_name="azqueue", queue_name="{YOUR_QUEUE_NAME}", connection="AzureWebJobsStorage")
def ProcessMessageFunction(azqueue: func.QueueMessage):
try:
# Log the received message
logging.info("Received message: %s", azqueue.get_body())
# Decode the message body
message_body = azqueue.get_body().decode('utf-8')
logging.info('Decoded message: %s', message_body)
# Validate that the message is a URL
if not message_body.startswith("http"):
raise ValueError(f"Invalid URL format: {message_body}")
# Placeholder for URL processing logic
# This is where the URL would be processed
result = process_single_url("{BASE_URL}", message_body)
logging.info('Processing result: %s', result)
except requests.exceptions.RequestException as e:
logging.error("Network-related error: %s", str(e))
except ValueError as ve:
logging.error("Value error: %s", str(ve))
except Exception as e:
logging.error("Unhandled error: %s", str(e))
logging.exception("Exception details:")
Я не могу выяснить причину этой ошибки, поскольку не получаю достаточно информации, даже при запуске func start --verboseМой файл host.json выглядит так:
Код: Выделить всё
{
"version": "2.0",
"logging": {
"logLevel": {
"Function": "Debug",
"Host.Results": "Error",
"Host.Aggregator": "Trace",
"Queues": "Debug"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Код: Выделить всё
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsAccountName": "{YOUR_ACCOUNT_NAME}",
"AzureWebJobsStorage": "AccountName={YOUR_ACCOUNT_NAME};AccountKey={YOUR_ACCOUNT_KEY};DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/{YOUR_ACCOUNT_NAME};QueueEndpoint=http://127.0.0.1:10001/{YOUR_ACCOUNT_NAME};TableEndpoint=http://127.0.0.1:10002/{YOUR_ACCOUNT_NAME};",
"PCAOB_BASE_URL": "http://localhost:5000"
}
}
Код: Выделить всё
azure-common==1.1.28
azure-core==1.30.2
azure-functions==1.20.0
azure-identity==1.16.0
azure-storage-blob==12.20.0
azure-storage-queue==12.11.0
Я просто пытаюсь отладить проблему. Пока что вывод о том, что предел MaxDequeueCount достигнут, — единственное, что я получаю, и это бесполезно.
Любые советы приветствуются
Подробнее здесь: https://stackoverflow.com/questions/788 ... ng-message