Self hosting

Component: NServiceBus | Nuget: NServiceBus (Version: 6.x)

Code walk-through

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

Edit
var endpointConfiguration = new EndpointConfiguration("Samples.SelfHosting");
endpointConfiguration.UseSerialization<JsonSerializer>();
endpointConfiguration.EnableInstallers();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.SendFailedMessagesTo("error");

var endpointInstance = await Endpoint.Start(endpointConfiguration)
    .ConfigureAwait(false);
try
{
    Console.WriteLine("\r\nBus created and configured; press any key to stop program\r\n");
    var myMessage = new MyMessage();
    await endpointInstance.SendLocal(myMessage)
        .ConfigureAwait(false);
    Console.ReadKey();
}
finally
{
    await endpointInstance.Stop()
        .ConfigureAwait(false);
}

Related Articles

  • Hosting
    Outlines the various approaches to endpoint hosting.

Last modified