0
votes

I have a MassTransit routing slip with a couple of activities that works perfectly (I love MT) but I now want to add additional information to the failed events (i.e. error name and description).

At the moment I catch my custom exceptions in the activity and send back a faulted response, which kicks in all of the compensating activites as planned, but I can't seem to get the exception details in the subscriber (to add to the event I then send back to the saga).

My activity looks like this:

public async Task<ExecutionResult> Execute(ExecuteContext<ICreateLink> context)
        {
            var messageCommand = context.Arguments;

            var command = new CreateLink(
                messageCommand.LinkId,
                messageCommand.GroupId);
            try
            {
                await _commandDispatcher.ExecuteAsync(command).ConfigureAwait(false);
                return context.Completed();
            }
            catch (Exception ex)
            {
                return context.Faulted(ex);
            }
        }

Then when building the routing slip I have:

builder.AddSubscription(
                context.SourceAddress,
                RoutingSlipEvents.ActivityFaulted,
                RoutingSlipEventContents.All,
                nameof(CreateLinkActivity),
                x => x.Send<ICreateLinkFailed>(new CreateLinkFailed
                {
                    LinkId = context.Message.LinkId,
                    LinkName = context.Message.Name
                }));

I thought I would be able to access the exception information from the context but alas I can't seem to find it and this is the last piece of the puzzle for me.

I'm beginning to think that I'm not thinking about this right. Ultimately I want to pass the error type back to the routing slip and then to it's calling saga.

1

1 Answers

2
votes

With your subscription, your event type can include properties with the same type/name as the built-in event that is published. Those properties will be added by MT to the event automatically (no need to map them in the Send call).

https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit/Courier/Contracts/RoutingSlipActivityFaulted.cs#L19

So in your case, the ExceptionInfo property could be copied into your event interface - and that data will be presented when the event is consumed.

Under the hood, MassTransit merges the JSON of the built-in event and your own event assignment into a combined JSON document.