Skip to content
Ioan Crișan edited this page Mar 18, 2019 · 5 revisions

A special case of messages are events. Unlike typical message handling, for events there can be more than one handler.

  • Publish events using the IEventPublisher service.
  • Subscribe to events using the IEventHub service.

Publishing messages

Events are published through the event publisher service.

    var eventPublisher = compositionContext.GetExport<IEventPublisher>();
    eventPublisher.Publish(new AppStartedEvent());

Typed messages

Untyped messages

See IdentifiableEvent.

Subscribing to events

The central point for event subscription is the event hub service.

    var eventHub = compositionContext.GetExport<IEventHub>();
    var subscription = eventHub.Subscribe<AppStartedEvent>((_, _, _) => this.Logger.Info("Application started"));
    //...
    subscription.Dispose();

Event flow

  • An event is published through the event publisher service. Typically this is the DistributedEventPublisher implementation.
  • The event is transported using the message broker.
  • The EventHubMessageHandler endpoint receives the event and notifies all event hub subscribers.

Clone this wiki locally