Pause fetching new messages from Azure Service Bus in Azure Function

Viewed 45

I am creating an azure function using a service bus to make my API more resilient to high traffic spikes. However I am uncertain on how I should handle an offline database as the function still continues to fetch messages, eventually dead lettering messages.

Therefore I were thinking about implementing a check during the startup class of the function to automatically shut it down before fetching any events.

It would look something like this:

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        var settings = new MongoClientSettings();
        var mongoClient = new MongoClient(settings);
        mongoClient.StartSession();
        if(mongoCLient.Cluser.Description.State != MongoDB.Driver.Core.Clusters.CluseterState.Connected)
            throw new Exception("Db connection failed during startup")
    }
}

However as I am not certain on how the trigger really works i am wondering if there might be any issues i cant foresee. Its also quite hard to test properly.

Any thoughts, knowledge or potentially other ideas would be much appreciated. Thanks!

0 Answers
Related