I have 3 azure functions first is blob trigger, second is service bus queue trigger and third is service bus topic functions. The functions is running fine but now I have a requirement to have blob name in all the 3 functions which is helping to trigger the first functions. In blob trigger functions I can get blob name using path variable of input binding but I'm not able to find a way to pass this blob name variable to other two functions. Is it possible to pass this variable as a dynamic in bindings of other functions?
Asked
Active
Viewed 520 times
1
-
Hi, Any update? Can you work it out now? – Cindy Pau Nov 25 '20 at 10:17
-
Hi @BowmanZhu, I'm able to achieve it. Basically my first function is blob triggered and other function is related to service bus. so I'm sending json message containing filename and data to function2 from function1 and then from function2 to function3. Below is the approach I'm using. data = myblob.read().decode('utf-8') filename = myblob.name.split(os.path.sep)[-1] json_data = {"File":filename,"Body":data} msg.set(json_data) – sam Nov 27 '20 at 03:11
-
If my answer helps you, can you mark it as the answer to end this question?:) Thanks. – Cindy Pau Nov 27 '20 at 03:17
1 Answers
2
If you are talking about pass dynamic blob name with code, then it is not possible. This is because the blob name value of blob input binding or blob trigger is be designed as const.(So this must be setted before compile.)
The only way is to use the mechanism left at the beginning of the design.
You can do something like below:
__init__.py
import logging
import azure.functions as func
def main(msg: func.ServiceBusMessage, outputblob: func.Out[func.InputStream]):
logging.info('Python ServiceBus queue trigger processed message: %s',
msg.get_body().decode('utf-8'))
outputblob.set('111')
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "myqueue",
"connection": "bowman1012_SERVICEBUS"
},
{
"name": "outputblob",
"type": "blob",
"path": "{mypath}/111.txt",
"connection": "MyStorageConnectionAppSetting",
"direction": "out"
}
]
}
You can send json format message to service bus:
{
"mypath":"bowman"
}
Then you can send the blob to dynamic path you want:
In short, it is impossible to use encoding. You can only achieve it through the things left at the beginning of the azure function design.

Cindy Pau
- 13,085
- 1
- 15
- 27
-
But still blob name is fixed here. I'm also rhinking to send json msg to service queue but not able to find a way or reference. Could you refer some documents or link where I can check for json passing to queue or can you give some example on this. I was thinking send json in which i wil give two param one is blob name and other is queue msg. – sam Nov 18 '20 at 02:51
-
@sam This is the method to send message:https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.servicebus.queueclient.sendasync?view=azure-dotnet#Microsoft_Azure_ServiceBus_QueueClient_SendAsync_Microsoft_Azure_ServiceBus_Message_ and set property to send json format: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.servicebus.message?view=azure-dotnet#properties You can first try to do it yourself with the connection given above. I have something to do and I need to go out. If you can't do it, I will come back and update you with a simple example. – Cindy Pau Nov 18 '20 at 03:00
-
@sam By the way, if you are not satisfied with the format of the binding, you can use the SDK directly, which may be more free. (And the binding is also based on the servicebus sdk, but if it is binding, the value can only be obtained through json.) – Cindy Pau Nov 18 '20 at 03:02