Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Is it posisble to add dynamic data to an MassTransit courier/routing slip custom event?

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 8 months ago )

I have a MassTransit routing slip configured and working. For reference, the routing slip takes in an ID of an item in a MongoDB database and then creates a "version" of that document in a SQL database using EF Core. The activities (as commands) are:

  1. Migrate document to SQL
  2. Update audit info in MongoDB document
  3. Update MongoDB document status (i.e. to published)

All of the above are write commands.

I have added a new 1st step which runs a query to make sure the MongoDB document is valid (e.g. name and description fields are completed) before running the migration. If this step fails it throws a custom exception, which in turns fires a failed event which is then picked up and managed by my saga. Below is a snippet of my activity code followed by the routing slip builder code:

Activity code

var result = await _queryDispatcher.ExecuteAsync<SelectModuleValidationResultById, ModuleValidationResult>(query).ConfigureAwait(false);

if (!result.ModuleValidationMessages.Any())
{
    return context.Completed();
}

return context.Faulted(new ModuleNotValidException
{
    ModuleId = messageCommand.ModuleId,
    ModuleValidationMessages = result.ModuleValidationMessages
});

Routing slip builder code

builder.AddActivity(
    nameof(Step1ValidateModule),
    context.GetDestinationAddress(ActivityHelper.BuildQueueName<Step1ValidateModule>(ActivityQueueType.Execute)),
    new SelectModuleValidationResultById(
        context.Message.ModuleId,
        context.Message.UserId,
        context.Message.LanguageId)
);

builder.AddSubscription(
    context.SourceAddress,
    RoutingSlipEvents.ActivityFaulted,
    RoutingSlipEventContents.All,
    nameof(Step1ValidateModule),
    x => x.Send<IModuleValidationFailed>(new
    {
        context.Message.ModuleId,
        context.Message.LanguageId,
        context.Message.UserId,
        context.Message.DeploymentId,
    }));

Whilst all of this works and the event gets picked up by my saga I would ideally like to add the ModuleValidationMessages (i.e. any failed validation messages) to the event being returned but I can't figure out how or even if that's possible (or more fundamentally if it's right thing to do).

It's worth noting that this is a last resort check and that the validation is checked by the client before even trying the migration so worse case scenario I can just leave it has "Has validation issues" but ideally I would like to include the derail in the failed response.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif