Controlling what is subscribed

Component: NServiceBus | Nuget: NServiceBus (Version: 3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

Automatic subscriptions

The default mode for managing subscriptions is auto subscribe. When a subscriber endpoint is started, it determines which events it needs to subscribe to. The endpoint then sends subscription messages to the publisher endpoint for those messages. This auto subscription mechanism happens each time the subscriber is restarted.

Messages matching the following criteria will be auto subscribed at startup.

  1. Defined as an event either using IEvent or by the .DefiningEventsAs convention.
  2. At least one message handler and/or saga exists for the given event.
  3. If the selected transport does not support publish-subscribe natively, the publisher for that message needs to be specified via the routing API.

Exclude sagas from auto subscribe

Events that are only handled by sagas are not subscribed to by default.

Auto subscribe to plain messages

This is a bad practice. Subscriptions should always be based on events.

In Version 3 all messages not defined as a command using ICommand or the .DefiningCommandsAs convention are automatically subscribed.

When a subscriber stops or uninstalls

A Subscriber will not unsubscribe when it stops, it will remain registered at the publisher to receive events. The publisher still sends events to the queue of the stopped subscriber. When the subscriber is started it will consume the messages from its queue. The subscriber will never lose an event.

Manually subscribing to a message

Events can manually be subscribed and unsubscribed:

Edit
bus.Subscribe<MyEvent>();

bus.Unsubscribe<MyEvent>();

Last modified