AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Handlers and Sagas

Component:
NServiceBus

There are two standard ways of executing code when a message is processed: handlers and sagas.

Handler instances are instantiated on a per-message basis, executed, and then disposed of. These are sometimes referred to as "stateless handlers".

Saga instances are also instantiated on a per-message basis, executed, and then disposed of. However they differ from handlers in that, once instantiated, they are passed an instance of a "Data" class. The "Saga Data" is the persisted state for an instance of a given saga type that is identified by a key. These are sometimes referred to as "stateful handlers".

Other concepts that both handlers and sagas share:

List of Samples

Related Articles

  • Handlers
    Write a class to handle messages in NServiceBus.
  • Sagas
    Master NServiceBus sagas to coordinate distributed workflows and ensure reliable long-running processes.