I have a azure function with Service Bus Topic Trigger. Every time the service bus topic receives a message, this function gets triggered.
I added the output binding to Blob Storage using:
But when the function runs, I do not see any output in blob storage. I am sure I am missing some basic code.
I saw multiple samples but every sample is using Blob Storage trigger.
CodePudding user response:
I have reproduced in my environment and got expected results and I followed the below process:
In my run.csx:
using System;
using System.Threading.Tasks;
public static void Run(string myQueueItem, ILogger log,ICollector<string> outputQueueItem)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
outputQueueItem.Add(myQueueItem);
}
In my Integration i added output as below:
In function.json:
{
"bindings": [
{
"name": "myQueueItem",
"connection": "Con",
"queueName": "rithwik",
"direction": "in",
"type": "serviceBusTrigger"
},
{
"name": "outputQueueItem",
"direction": "out",
"type": "queue",
"connection": "AzureWebJobsStorage",
"queueName": "outqueue"
}
]
}
Sent message in Service bus queue as below:
In my stoarge account a new queue is created as below and I got the message too:
So you need to add ouputQueueItem.Add
inside the code and ICollector<string> outputQueueItem
in parameters as my example. Now you will get output also as I have got.
Edit:
I have added few lines in my code please check:
run.csx:
using System;
using System.Threading.Tasks;
public static void Run(string myQueueItem, ILogger log,ICollector<string> outputQueueItem,TextWriter outputBlob)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
outputQueueItem.Add(myQueueItem);
outputBlob.WriteLine(myQueueItem);
}
function.json:
{
"bindings": [
{
"name": "myQueueItem",
"connection": "Con",
"queueName": "rithwik",
"direction": "in",
"type": "serviceBusTrigger"
},
{
"name": "outputQueueItem",
"direction": "out",
"type": "queue",
"connection": "AzureWebJobsStorage",
"queueName": "outqueue"
},
{
"name": "outputBlob",
"direction": "out",
"type": "blob",
"path": "outcontainer/{rand-guid}",
"connection": "AzureWebJobsStorage"
}
]
}
In integration:
Container and blob got created as below:
Inside container:
So, I am making few changes such as TextWriter
as parameter and WriteLine inside code we can get expected results, hope this clears your doubt.