2024-01-25 13:51:48 +00:00
|
|
|
using Elsa.Extensions;
|
2023-01-01 17:02:38 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2024-02-16 13:00:28 +00:00
|
|
|
using Elsa.Hosting.Management.Contracts;
|
2024-02-26 14:21:33 +00:00
|
|
|
using Elsa.Hosting.Management.Features;
|
2024-01-25 13:51:48 +00:00
|
|
|
using Elsa.MassTransit.Consumers;
|
Implement dispatch channels (#4949)
* Add DispatchWorkflowOptions and update MassTransit configuration
Introduced a new class `DispatchWorkflowOptions` to provide workflow dispatch options. Updated MassTransit configuration to include NET6.0 and NET7.0 support, and ensure correct MassTransit version usage per target framework version.
* Add support for configurable MassTransit message dispatching
Implemented a feature which allows for configurable MassTransit message dispatching. Added support for specifying channels and message brokers. Message dispatching code was massively refactored and relevant endpoints and response models were updated to support new message dispatching features.
* Add IEndpointChannelFormatter interface and implementation
An interface for formatting channel queue names, 'IEndpointChannelFormatter', has been added, along with its default implementation 'DefaultEndpointChannelFormatter'. The code that uses hardcoded queue name formatting has been modified to use the new formatter instead, making it more configurable and reusable. The implementation of the formatter uses the 'Humanizer' library to kebab-case the channel names.
* Add channel dispatch option to workflow activities
Introduced `WorkflowDispatcherChannelOptionsProvider` to provide dropdown channel options for workflow dispatch-related activities. Updated `DispatchWorkflow` and `BulkDispatchWorkflows` activities to include a new dropdown input for specifying a dispatch channel. Also, included the selected channel name in the `DispatchWorkflowOptions` during workflow dispatching process.
* Update MassTransit configurations and remove unused code
The MassTransit setup in Elsa.MassTransit module has been simplified by removing conditional code for different .NET versions. Additionally, unused parameter '__X_Channel' in 'DispatchWorkflowDefinition' was removed. Lastly, the MassTransit broker in Elsa.Server.Web was switched from RabbitMq to AzureServiceBus.
* Refactor dispatch workflow classes and methods
Simplified the class, method and variable names related to workflow dispatching in the Elsa.Workflows.Runtime module. For example, the 'WorkflowDispatcherChannelDescriptor' class was renamed to 'DispatcherChannel'. This refactoring was performed to make code more readable and maintainable by removing redundant wording in the naming convention.
* Update GitHub Workflow to support feature and issue branches
The workflow changes add support for feature and issue branches. Now, it extracts the branch name and verifies the commit exists in the given branch rather than just 'main'. The versioning scheme is also modified to include the branch name and not just the run number.
* Add 'bug/*' to triggering branches in packages workflow
The 'bug/*' pattern was missing from the triggers that initiate the GitHub actions within our packages workflow. This update includes any branch with a 'bug/' prefix to the list, allowing bug-related branches to start jobs in our CI/CD pipeline.
* Remove 'issue/*' and 'bug/*' branches from packages workflow
The 'issue/*' and 'bug/*' branches have been removed from the GitHub action workflow for packages. This change was made to simplify the workflow and optimize the triggering of package building.
* Update GitHub workflow to handle main branch versioning
This commit modifies the GitHub workflow script to accommodate changes when the branch name is "main." If the branch name is "main", a preview version is used. It also updates script execution to print the branch name for easier debugging and verifies commit existence on the correct branch instead of dispatch channels.
* Enclose branch names in quotes in packages.yml
The update modifies the branch names in the packages.yml GitHub Actions workflow file. The change consists of enclosing the branch names 'main' and 'feature/*' in single quotes, ensuring compatibility and preventing potential string interpretation issues.
* Update GitHub workflows package configuration
The workflows package configuration has been updated to specifically watch for changes on 'feature/dispatch-channels' rather than on all feature branches. This change will prevent unnecessary builds on less relevant feature branches.
* Update trigger branches in packages workflow
The triggering branches in the packages workflow have been updated. Previously, only changes in the 'main' and 'feature/dispatch-channels' would trigger the workflow, now any 'feature/*' branch will. This will cause more frequent and comprehensive testing.
* Add 'patch/*' to workflow trigger branches
This update adds 'patch/*' to the list of branches in .github/workflows/packages.yml that can trigger the workflow. It will allow the workflow to be initiated not just for main and feature branches, but also for patches.
* Add 'preview/*' to workflow triggers
This commit adds a new trigger for the GitHub Actions workflow. It now also responds to push events on 'preview/*' branches, allowing for automated testing and building of these preview branches.
* Update branch name extraction in GitHub Actions
The extraction of the branch name has been slightly modified in the packages.yml GitHub workflow file. This alteration ensures the correct branch name is obtained for further processing within the workflow without any discrepancy.
* Update branch name extraction in packages.yml
Corrected the syntax for extracting the branch name within the packages.yml github workflow file. Added an extra line to print out the ref which might be useful for debugging.
* Update branch name extraction in GitHub workflow
The commit simplifies the way the branch name is being extracted from the GitHub ref in the packages.yml workflow file. The new method employs straightforward string manipulation, making it easier to understand and debug in case of potential issues.
* Add extraction of branch name in workflow
Added a new line in the GitHub workflow file (.github/workflows/packages.yml) to extract the last part after the final slash from the branch name. This enhancement allows cleaner naming conventions, especially in cases where branches are named feature/issue-123, as it will only retain 'issue-123'.
* Update package naming in Github workflow
The Github workflow has been updated to handle package naming more effectively. Previously, the branch name was used directly for package versioning. Now, the last part of the branch name is extracted and used as the package prefix. If the branch name is "main", the package prefix is set to "preview".
* Move and add environment variable assignments
The placement of the assignment for BRANCH_NAME environment variable was moved for better readability. Additionally, the PACKAGE_PREFIX environment variable was also added. These environment variables are crucial for subsequent steps in the GitHub workflow.
* Add workflow dispatch validation and response handling
Removed several specific dispatch response classes and consolidated all types of dispatch responses into a single DispatchWorkflowResponse class. Added a new ValidatingWorkflowDispatcher service to validate dispatch requests before they're sent. Updated several classes to work with these changes, including the BackgroundWorkflowDispatcher, MassTransitWorkflowDispatcher, and the API endpoint class.
* Handle dispatch workflow failures with exceptions
The DispatchWorkflow and BulkDispatchWorkflows activities now throw a FaultException when the dispatch operations fail. Previously, these operations were not checking for success and could fail silently. Now, an unsuccessful dispatch response results in a FaultException with an error message from the dispatch response.
2024-02-16 09:56:30 +00:00
|
|
|
using Elsa.MassTransit.Extensions;
|
2023-11-15 19:47:11 +00:00
|
|
|
using Elsa.MassTransit.Features;
|
2024-01-25 13:51:48 +00:00
|
|
|
using Elsa.MassTransit.Options;
|
2023-01-01 17:02:38 +00:00
|
|
|
using MassTransit;
|
2023-12-11 18:59:13 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-01-25 13:51:48 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2023-01-01 17:02:38 +00:00
|
|
|
|
2023-11-15 19:47:11 +00:00
|
|
|
namespace Elsa.MassTransit.RabbitMq.Features;
|
2023-01-01 17:02:38 +00:00
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
2023-11-15 19:47:11 +00:00
|
|
|
/// Configures MassTransit to use the RabbitMQ transport.
|
2023-01-04 14:28:28 +00:00
|
|
|
/// </summary>
|
2023-01-01 17:02:38 +00:00
|
|
|
[DependsOn(typeof(MassTransitFeature))]
|
2024-02-26 14:21:33 +00:00
|
|
|
[DependsOn(typeof(InstanceManagementFeature))]
|
2023-01-01 17:02:38 +00:00
|
|
|
public class RabbitMqServiceBusFeature : FeatureBase
|
|
|
|
|
{
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <inheritdoc />
|
2023-01-01 17:02:38 +00:00
|
|
|
public RabbitMqServiceBusFeature(IModule module) : base(module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// A RabbitMQ connection string.
|
2023-12-11 18:59:13 +00:00
|
|
|
public string? ConnectionString { get; set; }
|
2023-01-01 17:02:38 +00:00
|
|
|
|
2024-03-30 20:22:35 +00:00
|
|
|
/// <summary>
|
2023-12-11 18:59:13 +00:00
|
|
|
/// Configures the RabbitMQ transport options.
|
2024-03-30 20:22:35 +00:00
|
|
|
/// </summary>
|
2023-12-11 18:59:13 +00:00
|
|
|
public Action<RabbitMqTransportOptions>? TransportOptions { get; set; }
|
2024-02-16 13:00:28 +00:00
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
2023-12-11 18:59:13 +00:00
|
|
|
/// Configures the RabbitMQ bus.
|
2023-01-04 14:28:28 +00:00
|
|
|
/// </summary>
|
2023-12-11 18:59:13 +00:00
|
|
|
public Action<IRabbitMqBusFactoryConfigurator>? ConfigureServiceBus { get; set; }
|
2023-01-04 14:28:28 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2023-01-01 17:02:38 +00:00
|
|
|
public override void Configure()
|
|
|
|
|
{
|
2024-01-25 13:51:48 +00:00
|
|
|
Module.Configure<MassTransitFeature>(massTransitFeature =>
|
2023-01-01 17:02:38 +00:00
|
|
|
{
|
2024-01-25 13:51:48 +00:00
|
|
|
massTransitFeature.BusConfigurator = configure =>
|
2023-01-01 17:02:38 +00:00
|
|
|
{
|
2024-03-29 19:43:39 +00:00
|
|
|
var temporaryConsumers = massTransitFeature.GetConsumers()
|
2024-02-16 13:00:28 +00:00
|
|
|
.Where(c => c.IsTemporary)
|
2024-01-25 13:51:48 +00:00
|
|
|
.ToList();
|
2024-03-29 19:43:39 +00:00
|
|
|
|
|
|
|
|
// Consumers need to be added before the UsingRabbitMq statement to prevent exceptions.
|
|
|
|
|
foreach (var consumer in temporaryConsumers)
|
|
|
|
|
configure.AddConsumer(consumer.ConsumerType).ExcludeFromConfigureEndpoints();
|
|
|
|
|
|
2024-02-20 11:55:02 +00:00
|
|
|
configure.UsingRabbitMq((context, configurator) =>
|
2024-01-25 13:51:48 +00:00
|
|
|
{
|
2024-04-03 21:32:50 +00:00
|
|
|
var options = context.GetRequiredService<IOptions<MassTransitOptions>>().Value;
|
2024-02-16 13:00:28 +00:00
|
|
|
var instanceNameProvider = context.GetRequiredService<IApplicationInstanceNameProvider>();
|
|
|
|
|
|
2024-01-25 13:51:48 +00:00
|
|
|
if (!string.IsNullOrEmpty(ConnectionString))
|
2024-02-20 11:55:02 +00:00
|
|
|
configurator.Host(ConnectionString);
|
2023-12-11 18:59:13 +00:00
|
|
|
|
2024-04-03 21:32:50 +00:00
|
|
|
if (options.PrefetchCount is not null)
|
|
|
|
|
configurator.PrefetchCount = options.PrefetchCount.Value;
|
|
|
|
|
configurator.ConcurrentMessageLimit = options.ConcurrentMessageLimit;
|
|
|
|
|
|
2024-02-20 11:55:02 +00:00
|
|
|
ConfigureServiceBus?.Invoke(configurator);
|
2024-02-16 13:00:28 +00:00
|
|
|
|
2024-03-29 19:43:39 +00:00
|
|
|
foreach (var consumer in temporaryConsumers)
|
2024-01-25 13:51:48 +00:00
|
|
|
{
|
2024-02-20 11:55:02 +00:00
|
|
|
configurator.ReceiveEndpoint($"{instanceNameProvider.GetName()}-{consumer.Name}",
|
2024-03-29 19:43:39 +00:00
|
|
|
endpointConfigurator =>
|
2024-02-20 11:55:02 +00:00
|
|
|
{
|
2024-03-29 19:43:39 +00:00
|
|
|
endpointConfigurator.QueueExpiration = options.TemporaryQueueTtl ?? TimeSpan.FromHours(1);
|
|
|
|
|
endpointConfigurator.ConcurrentMessageLimit = options.ConcurrentMessageLimit;
|
2024-04-03 21:32:50 +00:00
|
|
|
endpointConfigurator.Durable = false;
|
|
|
|
|
endpointConfigurator.AutoDelete = true;
|
2024-03-29 19:43:39 +00:00
|
|
|
endpointConfigurator.ConfigureConsumer(context, consumer.ConsumerType);
|
2024-02-20 11:55:02 +00:00
|
|
|
});
|
2024-01-25 13:51:48 +00:00
|
|
|
}
|
2023-12-11 18:59:13 +00:00
|
|
|
|
Minor improvements and bug fixes following the 3.1 release (#5168)
* Move DynamicActivity.cs to Activities directory
The DynamicActivity.cs file has been moved from the Models directory to the Activities directory. This reorganization aims to ensure that the file's location correctly reflects its namespace.
* Add GetOutput method in ActivityExtensions
A new GetOutput method has been added to the ActivityExtensions.cs file. This method allows the retrieval of output with a specific name from an activity. Useful for handling complex types in workflow activities.
* Add feature check and refactor dependencies in Elsa
The commit introduces a new feature check in the `Module` class and refactors the dependencies in MassTransit features. Specifically, it enables querying for a specific feature before configuring the dispatcher endpoints, increasing flexibility and control. In addition, the responsibility for creating `IEndpointChannelFormatter` has been shifted from `MassTransitWorkflowDispatcherFeature` to `MassTransitFeature`, aligning with responsibility distribution.
Fixes #5165
* Add HasFeature method to IModule interface
The IModule interface has been updated to include two methods, HasFeature<T>() and HasFeature(Type featureType). These methods are designed to check if a specific type of feature has been configured, enhancing the functionality provided by the interface.
* Add WorkflowRuntimeFeature dependency
Removed unused namespaces from WorkflowsApiFeature class and added a new dependency on WorkflowRuntimeFeature. This change enhances the code cleanliness and ensures all required dependencies are correctly linked.
* Add activity completion functionality to multiple contexts
This commit introduces multiple methods to handle activity completion across various contexts, including ActivityExecutionContext and ActivityCompletedContext. It also includes updates to bookmark serialization and the WorkflowRuntime. The resulting changes should improve handling of activity outcomes and status updates in the application flow.
* Handle null options in DefaultWorkflowRuntime
Added null-conditional operators to prevent potential NullReferenceExceptions in DefaultWorkflowRuntime. This change ensures that even if the 'options' object is null, the code will not throw an exception and will instead use default values where applicable.
* Add ElsaDbContextOptions to DbContextOptionsBuilder
A line of code is added to enable applying ElsaDbContextOptions as default in DbContextOptionsBuilder within PersistenceFeatureBase. This change specifies the use of ElsaDbContextOptions when configuring the context options, enhancing the database context setup in the EntityFrameworkCore.Common module.
* Remove whitespace in Elsa.Server.Web.csproj
This commit removes unnecessary whitespaces at the end of the ProjectReference and PackageReference elements, in the Elsa.Server.Web.csproj file. This improves the readability and alignment of the code and follows the best practice for XML file format.
* Add MongoDB to docker-compose.yml
A MongoDB service has been added to the docker-compose file. The configuration includes port mapping and volume mapping for MongoDB data storage. This allows more flexibility in our environment setup with MongoDB now being spun up automatically.
* Add collection check in MongoDbStore before bulk save
Adjusted code structure, and divided longer lines of code into smaller, multi-line chunks for better readability. This refactoring makes the underlying operations and structuring of the code more apparent, aiding in future code maintenance and understanding.
* Change target branch in packages.yml workflow
This commit modifies the Github actions workflow for packaging. The branch from which to fetch changes is now specified explicitly as 'origin/patch/3.1.1' instead of the default 'origin/main'. This adjustment is specific for package creation under certain conditions.
2024-04-02 05:41:46 +00:00
|
|
|
// Only configure the dispatcher endpoints if the Masstransit Workflow Dispatcher feature is enabled.
|
|
|
|
|
if (Module.HasFeature<MassTransitWorkflowDispatcherFeature>())
|
|
|
|
|
configurator.SetupWorkflowDispatcherEndpoints(context);
|
|
|
|
|
|
2024-02-20 11:55:02 +00:00
|
|
|
configurator.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("Elsa", false));
|
2024-01-25 13:51:48 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|
2023-01-01 17:02:38 +00:00
|
|
|
}
|
2023-12-11 18:59:13 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
|
|
|
|
if (TransportOptions != null) Services.Configure(TransportOptions);
|
|
|
|
|
}
|
2023-01-01 17:02:38 +00:00
|
|
|
}
|