简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM