NServiceBus is a library at its core so that it can be hosted in any .NET process.
There are several approaches to hosting.
Hosting with Microsoft.Extensions.Hosting
The Microsoft Generic Host is the standard way to host NServiceBus in modern .NET applications. Endpoints are registered on IServiceCollection using AddNServiceBusEndpoint.
For existing applications, NServiceBus.Extensions.Hosting and the UseNServiceBus integration remain supported.
Windows Service hosting
A Windows Service is a common way to host NServiceBus in Windows.
Related:
- Generic host as Windows Service
- Generate a Windows Service project using
dotnet new - Windows Service installation
Docker container hosting
An endpoint can be hosted inside a Docker container.
Related:
- Docker container host
- Generate a Docker-hosted endpoint project with
dotnet new - Hosting endpoints in Docker Linux containers
- Generic host
Send-only hosting
A "Send-only endpoint" is used when the only purpose is sending messages, and no message processing is required. Common use cases include websites, console applications, and Windows applications. This is the code for starting an endpoint in send-only mode.
var endpointConfiguration = new EndpointConfiguration("EndpointName");
endpointConfiguration.SendOnly();
The only configuration required when running in this mode is the destination when sending a message.
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.