0
votes

I'm implementing the claim check pattern with Azure Functions and Azure Service Bus.

My Azure Function has a ServiceBusTrigger, which works correctly by itself.

public async Task Run(
    [ServiceBusTrigger("worker", Connection = "SERVICE_BUS_CONNECTION")] string json,
    ILogger log)
{
    var notificationCommand = JsonConvert.DeserializeObject<NotificationCommand>(json, new JsonNotificationCommandConverter());

The serialized claim check messages from the bus look something like this:

{
    "type": "claim-check",
    "product": "XYZ", 
    "payloadRef": "https://{storage-account}/{container}/{blob_id}"
}

I would like to be able to just use a Blob input binding to get the payload reference from BLOB storage without having to do it manually, but I'm having some issues with the binding expressions - I'm not even sure if it's possible to do what I'm attempting...

Basically I want to do the following:

public async Task Run(
    [ServiceBusTrigger("worker", Connection = "SERVICE_BUS_CONNECTION")] string json,
    [Blob("{PayloadReference}", FileAccess.Read, Connection = "BLOB_STORAGE_CONNECTION")] Stream myBlob,
    ILogger log)
{
    var notificationCommand = JsonConvert.DeserializeObject<NotificationCommand>(json, new JsonNotificationCommandConverter());

where Blob("{PayloadReference}" refers to a property in the json message from the bus.

Is it possible? and if so how do I do it...

1
The blob attribute examples only show "{container}/{blob_id}". They don't show examples where the full uri is provided.camios
Not sure if it is a typo or even relevant, but I noticed the binding has "PayloadReference", but the payload field is shorter "payloadRef" and different case.camios

1 Answers

0
votes

C# use an imperative binding pattern, as opposed to the declarative bindings in function.json. So you can not put in json and let your output binding or input binding know the value of json format.

You can manually read value from the service bus queue or topic(from your service bus trigger) and use C# SDK for azure to send output to the blob path you want.