@Rajamannar A K As per your requirement you want to trigger your function app when the message is sent to the service bus queue so you need to add the input binding ("direction": "in") of type serviceBusTrigger
. Similarly, as you want to send the message to another queue when your business logic is completed then you need to add the output binding ("direction": "out") of type serviceBusTrigger
You can refer to Service Bus trigger Input and Service Bus Output binding for the usage and then customize it according to your need.
function.json
{
"scriptFile":"__init__.py",
"bindings":[
{
"name":"inputmsg",
"type":"serviceBusTrigger",
"direction":"in",
"queueName":"main",
"connection":"AzureServiceBusConnectionString"
},
{
"type":"serviceBus",
"direction":"out",
"connection":"AzureServiceBusConnectionString",
"name":"outputmsg",
"queueName":"outqueue"
}
]
}
init.py
import azure.functions as func
import logging
import json
def main(inputmsg: func.ServiceBusMessage,outputmsg: func.Out[str]):
logging.info('Python ServiceBus queue trigger processed message.')
result = json.dumps({
'message_id': inputmsg.message_id,
'body': inputmsg.get_body().decode('utf-8'),
'content_type': inputmsg.content_type,
'expiration_time': inputmsg.expiration_time,
'label': inputmsg.label,
'partition_key': inputmsg.partition_key,
'reply_to': inputmsg.reply_to,
'reply_to_session_id': inputmsg.reply_to_session_id,
'scheduled_enqueue_time': inputmsg.scheduled_enqueue_time,
'session_id': inputmsg.session_id,
'time_to_live': inputmsg.time_to_live,
'to': inputmsg.to,
'user_properties': inputmsg.user_properties,
'metadata' : inputmsg.metadata
}, default=str)
logging.info(result)
#you custom logic
output_msg = 'this is my custom message'
outputmsg.set(output_msg)