MassTransit Middleware for interface type

17 views
Skip to first unread message

Eddy Ma

unread,
Nov 13, 2018, 6:25:13 AM11/13/18
to masstransit-discuss
Hi

I got a MassTransit middleware that to persist all events into an event store, currently all events implement interface `IEvent`, here is my middleware

public async Task Send(T context, IPipe<T> next)
        {
            if (context is PublishContext<IEvent> publishContext)
            {
                await _eventService.InsertAsync(publishContext.Message);
            }
            await next.Send(context);
        }

My problem is Send is being called multiple times depends on the interface implemented by the event itself, looks like GreenPipe will hookup a pipe for each implemented interface, so how do I just handle the event once?

Thanks
Reply all
Reply to author
Forward
0 new messages