Releases: petar-m/EventBrokerSlim
3.0.0
What's Changed
Breaking Changes
IEventHandler<T>
methods now take parameterIRetryPolicy
instead ofRetryPolicy
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
What's Changed
Breaking Changes
IEventHandler<T>
methods take additional parameterRetryPolicy
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
- Update unit tests project dependencies (#8) (522f6a6 by @petar-m)
- Add retry feature (6abda82 by @petar-m)
- Output unit tests and code coverage as job summary (c33eff0 by @petar-m)
- Adjust unit test wait times (195a25d by @petar-m)
- Add global using in unit tests (9f994ad by @petar-m)
- Add Directory.Build.props, enable nullable types for unit tests (4b73463 by @petar-m)
- Update GitHub actions (83c30a3 by @petar-m)
- Use ImmutableArray for event handler descriptors (573e890 by @petar-m)
- Increase wait time on unit test (6477d03 by @petar-m)
- Run Code Cleanup for solution (bb03140 by @petar-m)
- Use NullLogger when logging not configured (283e528 by @petar-m)
- Adjust unit tests wait times (887c946 by @petar-m)
- Adjust unit tests wait times (de77467 by @petar-m)
- Adjust unit tests wait times (e13d843 by @petar-m)
- Remove 'Keyed' from EventHandlerRegistryBuilder methods (2880907 by @petar-m)
- Improve EventsRecorder false positives (2cff12d by @petar-m)
- Adjust unit tests wait times (4a46a0b by @petar-m)
1.0.0
1.0.0-preview3
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
1.0.0-preview1
Initial preview release.