Self hosting

Component: NServiceBus
NuGet Package NServiceBus (6.x)

Code walk-through

This sample shows how to host an in-process instance of NServiceBus.

var endpointConfiguration = new EndpointConfiguration("Samples.SelfHosting");

var endpointInstance = await Endpoint.Start(endpointConfiguration)
    Console.WriteLine("\r\nBus created and configured; press any key to stop program\r\n");
    var myMessage = new MyMessage();
    await endpointInstance.SendLocal(myMessage)
    await endpointInstance.Stop()
Although not shown in this sample, when self-hosting NServiceBus, the critical error action should always be overridden. If a critical error occurs, NServiceBus will stop the endpoint but will not shut down the process. By specifying a critical error action, the host application can elect to terminate in order to be respawned, or take action to notify system administrators of the failure.

Related Articles

  • Hosting
    Describes the various approaches to endpoint hosting.

Last modified