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/05/04 21:34] – skipidar | cloud:azure:functions [2024/05/19 14:36] (current) – skipidar | ||
---|---|---|---|
Line 225: | Line 225: | ||
Java SDK content | Java SDK content | ||
- | https:// | + | * 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.1714858453.txt.gz · Last modified: by skipidar