Skip to content

Releases: petar-m/EventBrokerSlim

3.0.0

02 May 11:36
Compare
Choose a tag to compare

What's Changed

Breaking Changes

  • IEventHandler<T> methods now take parameter IRetryPolicy instead of RetryPolicy

before:

public interface IEventHandler<TEvent>
{
    Task Handle(TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken);
    Task OnError(Exception exception, TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken);
}

after:

public interface IEventHandler<TEvent>
{
    Task Handle(TEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken);
    Task OnError(Exception exception, TEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken);
}

Commits

2.0.0

01 May 15:12
Compare
Choose a tag to compare

What's Changed

Breaking Changes

  • IEventHandler<T> methods take additional parameter RetryPolicy

before:

public interface IEventHandler<TEvent>
{
    Task Handle(TEvent @event, CancellationToken cancellationToken);
    Task OnError(Exception exception, TEvent @event, CancellationToken cancellationToken);
}

after:

public interface IEventHandler<TEvent>
{
    Task Handle(TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken);
    Task OnError(Exception exception, TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken);
}
  • EventHandlerRegistryBuilder registration methods renamed to omit 'Keyed' word

before:

services.AddEventHandlers(
            x => x.AddKeyedTransient<Event1, EventHandler1>()
                  .AddKeyedScoped<Event2, EventHandler2>()
                  .AddKeyedSingleton<Event3, EventHandler3>())

after:

services.AddEventHandlers(
            x => x.AddTransient<Event1, EventHandler1>()
                  .AddScoped<Event2, EventHandler2>()
                  .AddSingleton<Event3, EventHandler3>())

New Features

Retries

Retrying within event hadler can become a bottleneck. Imagine EventBroker is restricted to one concurrent handler. An exception is caught in Handle and retry is attempted after given time interval. Since Handle is not completed, there is no available "slot" to run other handlers while Handle is waiting.

Another option will be to use IEventBroker.PublishDeferred. This will eliminate the bottleneck but will itroduce different problems. The same event will be handled again by all handlers, meaning specaial care should be taken to make all handlers idempotent. Any additional information (e.g. number of retries) needs to be known, it should be carried with the event, introducing accidential complexity.

To avoid these problems, both IEventBroker Handle and OnError methods have RetryPolicy parameter.

RetryPolicy.RetryAfter() will schedule a retry only for the handler it is called from, without blocking. After the given time interval an instance of the handler will be resolved from the DI container (from a new scope) and executed with the same event instance.

RetryPolicy.Attempt is the current retry attempt for a given handler and event.
RetryPolicy.LastDelay is the time interval before the retry.

RetryPolicy.RetryRequested is used to coordinate retry request between Handle and OnError. RetryPolicy is passed to both methods to enable error handling and retry request entirely in Handle method. OnError can check RetryPolicy.RetryRequested to know whether Hanlde had called RetryPolicy.RetryAfter().

Caution: the retry will not be exactly after the specified time interval in RetryPolicy.RetryAfter(). Take into account a tolerance of around 50 milliseconds. Additionally, retry executions respect maximum concurrent handlers setting, meaning a high load can cause additional delay.

Commits

1.0.0

12 Jan 17:36
297ef76
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.0.0-preview3...1.0.0

1.0.0-preview3

06 Jan 13:07
cd8409f
Compare
Choose a tag to compare

What's Changed

  • Add deferred publishing by @petar-m in #5
  • Cancel deferred and pending tasks on shutdown by @petar-m in #6

Full Changelog: 1.0.0-preview2...1.0.0-preview3

1.0.0-preview2

01 Jan 13:05
68c5450
Compare
Choose a tag to compare

What's Changed

  • Enable separate EventBroker and event handlers registration by @petar-m in #2
  • Remove EventHandlerRegistryBuilder.Add method by @petar-m in #3
  • Use Guid instead of string for service key by @petar-m in #4

New Contributors

Full Changelog: 1.0.0-preview1...1.0.0-preview2

1.0.0-preview1

28 Dec 15:48
Compare
Choose a tag to compare

Initial preview release.