elsa-core/src/modules/Elsa.Workflows.Runtime/Contracts/IEventPublisher.cs
Sipke Schoorstra f7743a0fe6
Fix race condition in Distributed Workflow Runtime during same-workflow event publishing (#6538)
* Add asynchronous stimulus dispatching to workflow runtime

Introduced the BackgroundStimulusDispatcher and related components to enable asynchronous stimulus dispatching. Updated event publishing logic to support both synchronous and asynchronous delivery. These changes improve extensibility and allow better performance for handling workflow stimuli.

* Update event publishing to include isAsync parameter

Added a boolean parameter to differentiate between asynchronous and synchronous event publishing. Ensured correct value is passed based on workflow execution mode, improving clarity and functionality. Removed outdated TODO comment.

* Fix default value for Asynchronous and add activity type helper

Set the default value of the Asynchronous input property to `true` in `PublishEvent`. Additionally, utilize `ActivityTypeNameHelper` in `EventPublisher` to generate activity type names for improved consistency and clarity.

* Remove unused import from EventPublisher.cs

Eliminated the unnecessary import of Elsa.Workflows.Runtime.Requests. This cleanup helps reduce code clutter and improves maintainability.

* Set default value for Asynchronous property and update Payload.

Added a default value of `true` for the `Asynchronous` property to ensure consistency in event delivery behavior. Also, removed the unnecessary default value from the `Payload` property description for clarity.

* Simplify XML doc comment in IStimulusDispatcher interface

Refined the XML documentation for the `SendAsync` method by shortening the description and clarifying the statement. This improves readability and maintains the intent of the comment.

* Add MassTransit stimulus dispatching functionality

Introduced `DispatchStimulusRequestConsumer` and associated consumer definitions to enable stimulus dispatching. Added `MassTransitStimulusDispatcher` service and related options for configuring concurrency and endpoint behavior. Updated `MassTransitWorkflowDispatcherFeature` to register the stimulus dispatcher and allow enhanced dispatch configuration.

* Refactor stimulus dispatching to use a serialized message.

Introduced `DispatchStimulus` to encapsulate serialized requests. Updated dispatch logic to utilize `IPayloadSerializer` for serialization and deserialization, enabling message transport in a lightweight format.

* Remove Asynchronous input property from PublishEvent activity

The Asynchronous input property was removed as it was unnecessary, with a hardcoded `true` value now passed directly to the event publisher. This simplifies the code and ensures consistency in how events are published.

* Remove ProtoStringExtensions and consolidate string utilities.

Moved `EmptyIfNull` and `NullIfEmpty` methods to the existing `StringExtensions` class in `Elsa.Workflows.Core` for centralization. Updated references to use the consolidated extension methods. Deleted `ProtoStringExtensions` as it is now redundant.

* Add missing imports for Elsa.Extensions across mappers

Added `using Elsa.Extensions` to multiple mapper files in the runtime module. This ensures consistent access to shared extension methods, improving code clarity and reducing potential errors.

* Add missing Elsa.Extensions namespace to WorkflowInstance

The `using Elsa.Extensions` directive was added to ensure access to required extensions. This resolves potential issues with missing dependencies or functionality in the `WorkflowInstance` class.
2025-03-31 18:11:27 +02:00

14 lines
565 B
C#

using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.Runtime;
/// <summary>
/// Publishes events using the workflow runtime, effectively triggering all <see cref="Event"/> activities.
/// </summary>
public interface IEventPublisher
{
/// <summary>
/// Publishes the specified event.
/// </summary>
Task PublishAsync(string eventName, string? correlationId = null, string? workflowInstanceId = null, string? activityInstanceId = null, object? payload = null, bool asynchronous = false, CancellationToken cancellationToken = default);
}