Creating the microservice logic

The logic itself is relatively straightforward; however, you'll notice some gaps in here where we are using methods and classes that either don't exist or are not accessible. We'll start by putting our logic into a separate class; to make the class easy to understand, we'll create a public function called Run:

public async Task Run()
{
    while (true)
    {
        if (!await ProcessEachMessage())
        { 
            await Task.Delay(60000);
            continue;
        }
    }
}

The logic here is that we try to get the next message from the service bus; when we are not successful, we wait for a minute and try again. Let's see what ProcessEachMessage looks like:

public async Task<bool> ProcessEachMessage()
{
    SalesOrder.Models.SalesOrder? salesOrder = await _serviceBusHelper. ...

Get C# 8 and .NET Core 3 Projects Using Azure - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.