Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Modernization
Samples

Hosting

Component: NServiceBus
NuGet Package: NServiceBus 8.x
Standard support for version 8.x of NServiceBus has expired. For more information see our Support Policy.

NServiceBus is a library at its core so that it can be hosted in any .NET process.

There are several approaches to hosting.

Microsoft Generic Host

The Microsoft Generic Host is the most common way to host NServiceBus on .NET Core. NServiceBus integrates with the generic host using the NServiceBus.Extensions.Hosting package.

Self-hosting

"Self-hosting" is a general term used when the application code takes full control over all facets of hosting NServiceBus. This includes the following actions:

When self-hosting, the user is responsible for creating and starting the endpoint instance:

var endpointConfiguration = new EndpointConfiguration("EndpointName");
// Apply other necessary endpoint configuration, e.g. transport
var startableEndpoint = await Endpoint.Create(endpointConfiguration);
var endpointInstance = await startableEndpoint.Start();

// Shortcut
var endpointInstance2 = await Endpoint.Start(endpointConfiguration);

The user is also responsible for properly shutting down the endpoint when it is no longer needed (usually when the application terminates).

await endpointInstance.Stop();

Windows Service hosting

A Windows Service is a common way to host NServiceBus in Windows.

Related:

Docker container hosting

An endpoint can be hosted inside a Docker container.

Related:

Hosting technologies

Web hosting

NServiceBus can be hosted using any web technology that supports .NET. See Web Application Hosting for more information.

WebJob hosting

NServiceBus can be hosted in a WebJob. See Self-Hosting in Azure WebJobs

Serverless hosting

NServiceBus can be hosted in several serverless environments such as Azure Functions and AWS Lambda.

Hosting environment requirements

NServiceBus endpoints have certain requirements for the hosting environment:

  • The endpoint process needs write access to write log files. See the logging documentation for more details about the default log file location and how to configure logging.
  • The endpoint process needs write access to write the startup diagnostics file. See the startup diagnostics documentation for more details about the diagnostic file.
  • Since NServiceBus makes assumptions on aspects like assembly names, ILMerging any of the NServiceBus* assemblies is not supported.

Related Articles