Get an exception outside of Marten during a projection #2375
Replies: 2 comments
-
It's absolutely possible to get exceptions in the async projections. The daemon has configurable exception handling to do limited retries, or cooldown, or skip poison pill events |
Beta Was this translation helpful? Give feedback.
-
Currently here is my projection public class MartenAutoProjectionManager : IProjection
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<MartenAutoProjectionManager> _logger;
public MartenAutoProjectionManager(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
_logger = _serviceProvider.GetService<ILogger<MartenAutoProjectionManager>>();
}
public void Apply(IDocumentOperations operations, IReadOnlyList<StreamAction> streams)
{
throw new NotImplementedException();
}
public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList<StreamAction> streams, CancellationToken cancellation)
{
var events = streams.SelectMany(x => x.Events).OrderBy(s => s.Sequence).Select(s => s);
var projections = _serviceProvider.GetServices<Projections.Interfaces.IProjection>();
foreach (var @event in events)
{
await Task.WhenAll(projections.Select(x => x.Project(@event.Data, @event.Id.ToString())));
}
}
} I would like to be able to get triggered with the exception thrown + the I've seen error handling documentation https://martendb.io/events/projections/async-daemon.html#error-handling Thank you for your help |
Beta Was this translation helpful? Give feedback.
-
Hi,
following the advices from @oskardudycz I implemented the
IProjection
interface allowing me to have a custom behavior around the domain events stored into Postgres (event sourcing).I wonder if it's possible to get an exception thrown into the projection background worker ?
For example I intentionally made the deserialization fail (deleting/renaming the class of a domain event already serialized and stored in Postgres) to make the deserialization fail. I see Marten logging the
EventFetcherException
, but I would like to be given an access to it, adding some custom behavior (tracing, pushing external events and so on ...).For example, adding the following method to the IProjection interface + ad hoc implementation
EDITED on 02/11/22 (I misuse my internal IProjection interface instead of Marten's one ...)
Thank you very much for this awesome lib, my company has chosen it to implement ES in production.
Beta Was this translation helpful? Give feedback.
All reactions