0

I'm migrating my in process functions to isolated. While migrating I'm having this difficulty: It seems like ServiceBus's maxConcurrentCalls can only be set using host.json file.

{
    "version": "2.0",
    "extensions": {
        "serviceBus": {
            "clientRetryOptions":{
                "mode": "exponential",
                "tryTimeout": "00:01:00",
                "delay": "00:00:00.80",
                "maxDelay": "00:01:00",
                "maxRetries": 3
            },
            "prefetchCount": 0,
            "transportType": "amqpWebSockets",
            "webProxy": "https://proxyserver:8080",
            "autoCompleteMessages": true,
            "maxAutoLockRenewalDuration": "00:05:00",
            "maxConcurrentCalls": 16,
            "maxConcurrentSessions": 8,
            "maxMessageBatchSize": 1000,
            "minMessageBatchSize": 1,
            "maxBatchWaitTime": "00:00:30",
            "sessionIdleTimeout": "00:01:00",
            "enableCrossEntityTransactions": false
        }
    }
}

In the old process, in-process model, we were able handle the maxConcurrancy using appsettings.json

var serviceBusMaxConcurrentCalls = 
    Configuration.GetValue<int>("AppConfig:ServiceBus:Concurrency:MaxConcurrentCalls");

var serviceBusMaxConcurrentSessions = 
    Configuration.GetValue<int>("AppConfig:ServiceBus:Concurrency:MaxConcurrentSessions");

var serviceBusMaxConcurrentCallsPerSession = 
    Configuration.GetValue<int>("AppConfig:ServiceBus:Concurrency:MaxConcurrentCallsPerSession");

services.Configure<ServiceBusOptions>(options =>
    {
        options.MaxConcurrentCalls = serviceBusMaxConcurrentCalls;
        options.MaxConcurrentSessions = serviceBusMaxConcurrentSessions;
        options.MaxConcurrentCallsPerSession = serviceBusMaxConcurrentCallsPerSession;
        options.AutoCompleteMessages = false;
    }
);

Is there a way to still manage the concurrency using the appsettings? Or do we have to maintain an environment-specific host.json file?

1

1 Answer 1

0

If you want to keep you service bus configuration in appsettings, you'll have to add the configuration provider in your Program.cs file:

builder.Configuration
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables(); // Also adds env variables to the config if you need

Then if you like, create an options class around your appsettings.json. Using your example:

public class AppConfig
{
    public ServiceBus ServiceBus {  get; set; }
    // whatever else you need in your appsettings.json
}

public class ServiceBus  
{
    public Concurrency Concurrency { get; set; }
}

public class Concurrency
{
    public int MaxConcurrentCalls { get; set; }
    public int MaxConcurrentSessions { get; set; }
    public int MaxConcurrentCallsPerSession { get; set; }
}

You can add the following in your Program.cs to register the Options class:

builder.Services.Configure<AppConfig>(
    builder.Configuration.GetSection("AppConfig"));

And the following to configure service bus trigger concurrency like you want:

builder.Services.Configure<ServiceBusOptions>(options =>
{
    var settings = builder.Configuration
                          .GetSection("AppConfig")
                          .Get<AppConfig>();

    options.MaxConcurrentCalls = settings.ServiceBus.Concurrency.MaxConcurrentCalls;
    options.MaxConcurrentSessions = settings.ServiceBus.Concurrency.MaxConcurrentSessions;
    options.MaxConcurrentCallsPerSession = settings.ServiceBus.Concurrency.MaxConcurrentCallsPerSession;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.