Hi @ Zheng, Yu,
In ServiceBus Trigger V2 model of Python Function App, you cannot send session id, customer id's or broker properties as outbound, you can only hust send a message, but as an alternative you can use SDK to send to topic as below:
import azure.functions as func
import logging
from azure.servicebus import ServiceBusClient, ServiceBusMessage
import os
riapp = func.FunctionApp()
@riapp.service_bus_topic_trigger(
arg_name="azservicebus",
subscription_name="rithsub1",
topic_name="mysbtopic",
connection="demoser898_SERVICEBUS",
is_sessions_enabled=True
)
def servicebus_topic_trigger(azservicebus: func.ServiceBusMessage):
msg = azservicebus.get_body().decode("utf-8")
logging.info(f"Hello Rithwik, ServiceBus Topic trigger processed a message: {msg}")
cho_con = os.getenv("demoser898_SERVICEBUS")
sen_topic = "tp1"
servicebus_client = ServiceBusClient.from_connection_string(cho_con)
cho_sen = servicebus_client.get_topic_sender(sen_topic)
rith_msg = ServiceBusMessage("Rithwik Bojja")
rith_msg.session_id = "008"
with cho_sen:
cho_sen.send_messages(rith_msg)
logging.info(f"Rithwik, Forwarded message to topic: {sen_topic}.")
reuqirements.txt:
azure-functions
azure-servicebus
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
"demoser898_SERVICEBUS": "Endpoint=sb://demoser898.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=1zrithwikhhk=",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
Output:
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.