Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Integration Events

Marc Wittke edited this page Sep 29, 2018 · 1 revision

In addition to domain events that are handled in the same transaction and in the same process, an Integration Event is handled outside the transaction and even might be handled outside the process itself. Normally, an event bus is used to communicate events between processes. The InMemoryEventBus can be used to imitate this behavior inside the same process without setting up a real event bus.

Due to the distributed manner of Integration Events, multiple handling of the same event must be possible as well as resilency against network failures.

The interface IEventBus implies both, typed and untyped event handling.

public interface IEventBus : IDisposable
{
    void Connect();

    /// <summary>
    /// Directly publishes an event on the event bus without delay.
    /// In most cases you want to publish an event when the cause is considered as safely done, e.g. when the 
    /// wrapping transaction is committed. Use <see cref="IEventBusScope"/> to let the framework raise all events
    /// after committing the unit of work.
    /// </summary>
    /// <param name="integrationEvent"></param>
    /// <returns></returns>
    Task Publish(IIntegrationEvent integrationEvent);

    /// <summary>
    /// Subscribes to an integration event with a dynamic event handler
    /// </summary>
    /// <typeparam name="THandler">The handler type</typeparam>
    /// <param name="eventName">Th event name to subscribe to. (Should be Type.FullName to avoid namespace collisions)</param>
    void Subscribe<THandler>(string eventName)
        where THandler : IIntegrationEventHandler;

    /// <summary>
    /// Subscribes to an integration event with a generically typed event handler
    /// </summary>
    /// <typeparam name="THandler">The handler type</typeparam>
    /// <typeparam name="TEvent">The event type to subscribe to</typeparam>
    void Subscribe<THandler, TEvent>()
            where THandler : IIntegrationEventHandler<TEvent>
            where TEvent : IIntegrationEvent;

    void Unsubscribe<THandler>(string eventName)
        where THandler : IIntegrationEventHandler;

    void Unsubscribe<THandler, TEvent>()
            where THandler : IIntegrationEventHandler<TEvent>
            where TEvent : IIntegrationEvent;
}

Clone this wiki locally