Pankaj Rawat
Pankaj Rawat

Reputation: 4573

Services bus message receive in Azure Function

I created one ServicesBus queue and start sending thousands of messages

await queueClient.SendBatchAsync(brokeredMessagesList);

Another side I created azure function to receive messages form ServicesBus queue. here is my code

public static async Task RunAsync([ServiceBusTrigger("batch-input", AccessRights.Manage,
        Connection = "ServiceBusConnection")]BrokeredMessage message, TraceWriter log)
    {
        string body;
        using (var stream = message.GetBody<Stream>())
        using (var streamReader = new StreamReader(stream, Encoding.UTF8))
        {
            body = await streamReader.ReadToEndAsync();
        }
        SampleMessage sampleMessage = JsonConvert.DeserializeObject<SampleMessage>(body);

        await SaveMessageIntoAzureTableAsync(sampleMessage);
        //await message.CompleteAsync();
        log.Info($"Message body: {sampleMessage}");
    }

This code working in my local but I'm more curious about scaling and batch processing.

How azure function scaling will work with large no of message in queue?? I don't see any documentation

Prefetch Count setting will apply on local? here I saw default prefetching count is 100.

When should I call complete method (with or without this my code is working)?

await message.CompleteAsync();

Upvotes: 0

Views: 668

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

Functions runtime will retrieve messages in batches and call multiple function invocations in parallel. You can adjust Prefetch Count and some other settings with host.json file.

If queue size keeps growing, Azure will spin up more instances, which would also do processing in parallel.

You should never call CompleteAsync explicitly, this will be done for you by the runtime for any successful execution.

Upvotes: 2

Related Questions