cloud:azure:functions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cloud:azure:functions [2024/04/28 12:25] – skipidar | cloud:azure:functions [2024/05/19 14:36] (current) – skipidar | ||
|---|---|---|---|
| Line 38: | Line 38: | ||
| === Debugging Azure functions === | === Debugging Azure functions === | ||
| - | |||
| - | == Test execute and see output == | ||
| - | |||
| - | You can execute the Azure functions from the portal. | ||
| - | |||
| - | And you can validate the behavior via " | ||
| - | |||
| - | {{https:// | ||
| Line 58: | Line 50: | ||
| {{https:// | {{https:// | ||
| + | |||
| + | |||
| + | |||
| + | == Validate Files == | ||
| + | |||
| + | Often the files of Azure Function - are not deployed or lost after the terraform-update. | ||
| + | |||
| + | Check if the files are available and up to date. | ||
| + | |||
| + | Maybe teh reason why the trigger isnt there - is because you have not deplyoed the app? | ||
| + | |||
| + | {{https:// | ||
| + | |||
| + | |||
| + | == Test execute and see output == | ||
| + | |||
| + | You can execute the Azure functions from the portal. | ||
| + | |||
| + | And you can validate the behavior via " | ||
| + | |||
| + | {{https:// | ||
| Line 73: | Line 86: | ||
| - | |||
| - | |||
| - | == Validate Files == | ||
| - | |||
| - | Often the files of Azure Function - are not deployed or lost after the terraform-update. | ||
| - | |||
| - | Check if the files are up to date. | ||
| Line 206: | Line 212: | ||
| {{https:// | {{https:// | ||
| + | |||
| + | |||
| + | === Azure Functions Java === | ||
| + | |||
| + | https:// | ||
| + | |||
| + | <sxh java> | ||
| + | mvn clean install | ||
| + | mvn azure-functions: | ||
| + | mvn azure-functions: | ||
| + | </ | ||
| + | |||
| + | Java SDK content | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * | ||
| + | |||
| + | |||
| + | === Azure Service Topic Pub with session === | ||
| + | |||
| + | requirements.txt | ||
| + | <sxh python> | ||
| + | # DO NOT include azure-functions-worker in this file | ||
| + | # The Python Worker is managed by Azure Functions platform | ||
| + | # Manually managing azure-functions-worker may cause unexpected issues | ||
| + | |||
| + | azure-functions | ||
| + | datetime | ||
| + | azure-servicebus | ||
| + | |||
| + | </ | ||
| + | |||
| + | local.settings.json | ||
| + | <sxh python> | ||
| + | |||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | Python V2 app, which uses the Python SDK, to send messages with SessionId | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | <sxh python> | ||
| + | import logging | ||
| + | import azure.functions as func | ||
| + | from datetime import datetime | ||
| + | import json | ||
| + | from azure.servicebus import ServiceBusClient, | ||
| + | import os | ||
| + | |||
| + | app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) | ||
| + | |||
| + | # vs output into queue for python | ||
| + | # https:// | ||
| + | |||
| + | |||
| + | TOPIC_NAME_A = " | ||
| + | CONN_STRING = os.environ[' | ||
| + | SESSION_ID = " | ||
| + | |||
| + | |||
| + | @app.route(route=" | ||
| + | def http_trigger(req: | ||
| + | logging.info(' | ||
| + | myMessage = "Hi alf this is my message via the queue to you." | ||
| + | |||
| + | jsn_message_envelope = generateMessage(myMessage, | ||
| + | logging.info(f" | ||
| + | |||
| + | servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONN_STRING) | ||
| + | rith_sen = servicebus_client.get_topic_sender(TOPIC_NAME_A) | ||
| + | rith_msg = ServiceBusMessage(jsn_message_envelope) | ||
| + | rith_msg.session_id = SESSION_ID | ||
| + | with rith_sen: | ||
| + | rith_sen.send_messages(rith_msg) | ||
| + | servicebus_client.close() | ||
| + | |||
| + | |||
| + | return func.HttpResponse( | ||
| + | "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", | ||
| + | status_code=200 | ||
| + | ) | ||
| + | |||
| + | |||
| + | def generateMessage(myMessage, | ||
| + | now = datetime.now() | ||
| + | print(" | ||
| + | logging.info(f" | ||
| + | |||
| + | dt_string = now.strftime(" | ||
| + | |||
| + | my_json_string = f""" | ||
| + | {{ | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }}, | ||
| + | " | ||
| + | " | ||
| + | }} | ||
| + | }} | ||
| + | """ | ||
| + | |||
| + | return my_json_string | ||
| + | |||
| + | </ | ||
| + | |||
| + | == Publish a test message == | ||
| + | |||
| + | Publishing a message | ||
| + | |||
| + | {{https:// | ||
| + | |||
| + | And see, which session was used during publishing, here '' | ||
| + | |||
| + | {{https:// | ||
| + | |||
| + | == Consuming a test message == | ||
| + | |||
| + | Now a consumer can consume the message | ||
| + | |||
| + | {{https:// | ||
cloud/azure/functions.1714307121.txt.gz · Last modified: by skipidar
