Azure Function Isolated with QueueOutput and InitialVisibilityDelay

1.4k views Asked by At

Prior to Isolated Azure Functions, one could create an Output binding queue like so: [Queue(...)] CloudQueue outputQueue

Then, we could add a new message with the ability to add a Visibility Delay like so:

var cloudQueueMessage = new CloudQueueMessage("some message");
var timespan = new TimeSpan(0, 10, 0);

outputQueue.AddMessage(cloudQueueMessage, initialVisibilityDelay: timespan);

Now that we've migrated these Azure Function to the Isolated mode, how does one add a Visibility Delay to the message?

Here's an example from Microsoft's website enter image description here

How can we add a Visibility Delay to the message using the Isolated mode

Thank you

2

There are 2 answers

0
Vlince On BEST ANSWER

The following Microsoft documentation, explains why I can't achieve what I was able to do prior to Isolated mode. Isolated mode does not take advantage of those rich binding classes.

enter image description here

What I ended up doing was adding my own QueueClient and injecting it in my [Function]

enter image description here

  • At (1) I inject the QueueClient
  • At (2) I read the config file (local.settings.json) and then pass the value into an extension method to validate and/or set a fallback value. I then proceed to call the SendMessageAsync() with my message and with my visibility delay.
  • At (3) is the extension method (if anyone cares)

enter image description here

With all this in place, I can now achieve my initial goal and also prepare myself for any new features that might need to leverage specific stuff on the QueueClient that the bindings simply don't offer at the time of writing.

Thanks

1
Pravallika KV On
  • await Task.Delay(n)(task delay to simulate message processing) worked for me in Isolated Azure Functions C# Project to delay the Visibility of the message.
     [Function("Function1")]
        public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

            response.WriteString("Welcome to Azure Functions!");           
            for (var i = 0; i < 5; i++)
            {
                _logger.LogInformation($"Next visible {i}: {response.ToString()}");
                await Task.Delay(1000);
            }
            return response;

        }

Result:

enter image description here