Skip to content

MassTransit & CorrelationId in concurrent processes #6672

@krivovs

Description

@krivovs

Enhancement Request

Enhancement Overview

This Issue is a continuation of Issue#6336

Proposed Enhancement

According to MassTransit documentation there are some correlation conventions.
So in MassTransit library, if there is a property in the message with name "CorrelationId" of type "Guid" it will be used for CorrelationId.

Why not use a similar convention in Elsa MassTransit Feature when processing messages in WorkflowMessageConsumer? But instead of type "Guid" I suggest using type "string".

I've tested this code and it works fine.
`
public async Task Consume(ConsumeContext context)
{
var cancellationToken = context.CancellationToken;
var messageType = typeof(T);
var message = context.Message;
var activityTypeName = ActivityTypeNameHelper.GenerateTypeName(messageType);
var stimulus = new MessageReceivedBookmarkPayload(messageType);

    // =====================================================================
    // Looking for CorrelationId
    // =====================================================================
    // 1-st priority: from context
    string? correlationId = context.CorrelationId?.ToString();

    // 2-nd priority: from message, if one has property with name CorrelationId with type string 
    if (string.IsNullOrEmpty(correlationId))
    {
        PropertyInfo? property = messageType.GetProperty(CorrelationIdPropName, typeof(string));
        correlationId = property?.GetValue(message)?.ToString();
    }
    // =====================================================================

    var input = new Dictionary<string, object>
    {
        [MessageReceived.InputKey] = message
    };
    var stimulusMetadata = new StimulusMetadata
    {
        CorrelationId = correlationId,
        Input = input
    };
    await stimulusSender.SendAsync(activityTypeName, stimulus, stimulusMetadata, cancellationToken);
}

`

Please have a look at this, and consider including it in next release of Elsa.

It's just a couple of lines, but it takes off serious limitation of using MassTransit feature in concurrent processes.

Alternative Solutions

Use Cases

Impact of Enhancement

Visuals and Mockups

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions