elsa-core/src/modules/Elsa.MassTransit.RabbitMq/Features/RabbitMqServiceBusFeature.cs
Sipke Schoorstra 065765307b Refactor MassTransit & AzureServiceBus configuration and delete unnecessary options
AzureServiceBusOption.cs and RabbitMqOptions.cs files were removed as they're no longer needed. The system now defers the configuration of MassTransit and AzureServiceBus to the application layer (Program.cs). The configuration for PrefetchCount is also allowed at the transport-level. A new abstraction, ConsumerTypeDefinition, collects all the consumer types with their respective definitions if provided. Adjustments have been made in related extension methods and classes to reflect these changes.
2023-12-11 19:59:13 +01:00

54 lines
1.6 KiB
C#

using Elsa.Features.Abstractions;
using Elsa.Features.Attributes;
using Elsa.Features.Services;
using Elsa.MassTransit.Features;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.MassTransit.RabbitMq.Features;
/// <summary>
/// Configures MassTransit to use the RabbitMQ transport.
/// </summary>
[DependsOn(typeof(MassTransitFeature))]
public class RabbitMqServiceBusFeature : FeatureBase
{
/// <inheritdoc />
public RabbitMqServiceBusFeature(IModule module) : base(module)
{
}
/// A RabbitMQ connection string.
public string? ConnectionString { get; set; }
/// Configures the RabbitMQ transport options.
public Action<RabbitMqTransportOptions>? TransportOptions { get; set; }
/// <summary>
/// Configures the RabbitMQ bus.
/// </summary>
public Action<IRabbitMqBusFactoryConfigurator>? ConfigureServiceBus { get; set; }
/// <inheritdoc />
public override void Configure()
{
Module.Configure<MassTransitFeature>().BusConfigurator = configure =>
{
configure.UsingRabbitMq((context, serviceBus) =>
{
if (!string.IsNullOrEmpty(ConnectionString))
serviceBus.Host(ConnectionString);
ConfigureServiceBus?.Invoke(serviceBus);
serviceBus.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("Elsa", false));
});
};
}
/// <inheritdoc />
public override void Apply()
{
if (TransportOptions != null) Services.Configure(TransportOptions);
}
}