0

I have a azure function with Service Bus Topic Trigger. Every time the service bus topic receives a message, this function gets triggered.

enter image description here I added the output binding to Blob Storage using:

enter image description here

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.

2
  • Would be good to specify if you need the message body only or headers as well. Also, your code has no Blob Storage output binding. Commented Oct 25, 2022 at 14:19
  • @SeanFeldman: I only need the body of the request. I am new to Azure and my assumption was using output binding will do the needful (adding required output binding and attributes) Commented Oct 26, 2022 at 16:16

1 Answer 1

1

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);
}

enter image description here

In my Integration i added output as below:

enter image description here

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:

enter image description here

In my stoarge account a new queue is created as below and I got the message too:

enter image description here

enter image description here

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:

enter image description here

Container and blob got created as below:

enter image description here

Inside container:

enter image description here

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for quick reply. I wanted to add data to blob storage using Containers and not Queue.
@OpenStack, I have edited my answer according to your requirements(under edit header), I guess this will clear your doubt. I have given main points and other steps are same as my previous answer. If you dont want queues you can remove that too form code.
Accepted as answer. Can you please add more details how it is working. I read that we need to add output binding. Something like this: learn.microsoft.com/en-us/azure/azure-functions/… But your suggestion seems easier
@OpenStack, to be honest I haven't followed the document, TextWriter parameter is used to write the message or data into Blob and Write line is used in code and Coming to binding in function.json added output blob path and given the connection string, myQueueItem is the variable which contains message of the service bus is sent to storage account blob .
How can we append data ? if I set path of the container as container\data.txt instead of container\{rand-guid} how can I ensure data is always appended to file and we don't overwrite data in the file.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.