MessageHandler MH Sign Up

How to configure a handler runtime

C

The handler runtime configuration provides a configuration model which makes it possible to run the three processing engines together, or in isolation, as desired.

The foundation for this runtime configuration can be found in the MessageHandler.Runtime.Configuration nuget package.

PM> Install-Package MessageHandler.Runtime.Configuration

Note: Usually you don't need to explicitly install it, as it comes as a dependency of other packages already.

Integrating the runtime with a host

The most common scenario is to host the engines together, integrated in the dotnet generic hosting abstration or any of the framework provided derivatives, such as the ASP.NET Core Web Host

var builder = WebApplication.CreateBuilder(args);

Integrate MessageHandler into the host builder by calling the AddMessageHandler extension method for IServiceCollection. This will automatically create a new runtime configuration, integrate it with the hosts service collection and register any startup infrastructure for it.

builder.Services.AddMessageHandler("NameOfYourHandler", runtimeConfiguration =>
{
	
});

Configuring the runtime

The AddMessageHandler provides a callback that gives you access to the handler runtime configuration instance.

If not already set through the integration, it is always advised to set a name for your handler. Otherwise a name will be assigned based on the friendly name of the running app domain.

 runtimeConfiguration.HandlerName("NameOfYourHandler");

And, in case you are scaling your handler out, provide a unique instance id, potentially derived from your environment. If not specified, the handler name will be used instead.

runtimeConfiguration.HandlerInstanceId("IdOfThisInstance");

After this initial setup, you can extend the handler runtime configuration instance with respective processing engine configuration options, such as:

Setting up a runtime manually

If you want to take full controle of the startup sequence, you can configure a new runtime manually, by creating a new instance of HandlerRuntimeConfiguration.

You can optionally pass in an instance of IServiceCollection to the constructor. Do this in case you want to share dependencies between runtime instances.

 var runtimeConfiguration = new HandlerRuntimeConfiguration(services);

From the configuration you can create and start the runtime manually.

var runtime = HandlerRuntime.Create(runtimeConfiguration);
await runtime.Start();

Sign up to our newsletter to get notified about new content and releases

You can unsubscribe at any time by clicking the link in the footer of your emails. I use Mailchimp as my marketing platform. By clicking subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.