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.
- Defined as an event either using
IEventor by the
- At least one message handler and/or saga exists for the given event.
- If the selected transport does not support publish-subscribe natively, the publisher for that message needs to be specified via the routing API.
Sagas are treated the same as handlers and will cause an endpoint to subscribe to a given event. It is possible to opt-in to the old exclude saga event handling behavior using:
Configure.Features.AutoSubscribe(c => c.DoNotAutoSubscribeSagas());
In Version 4 and Version 5 it is possible to opt-in to automatically subscribe to all messages not defined as a command using
ICommand or the
.DefiningCommandsAs convention using the following code:
Configure.Features.AutoSubscribe(c => c.AutoSubscribePlainMessages());
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.
Automatic subscriptions by the infrastructure can be disabled using the configuration API:
Events can manually be subscribed and unsubscribed: