2023-01-01 17:02:38 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2023-11-15 19:47:11 +00:00
|
|
|
using Elsa.MassTransit.Features;
|
2023-01-01 17:02:38 +00:00
|
|
|
using MassTransit;
|
2023-12-11 18:59:13 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
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))]
|
|
|
|
|
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
|
|
|
|
2023-12-11 18:59:13 +00:00
|
|
|
/// Configures the RabbitMQ transport options.
|
|
|
|
|
public Action<RabbitMqTransportOptions>? TransportOptions { get; set; }
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
Module.Configure<MassTransitFeature>().BusConfigurator = configure =>
|
|
|
|
|
{
|
2023-12-11 18:59:13 +00:00
|
|
|
configure.UsingRabbitMq((context, serviceBus) =>
|
2023-01-01 17:02:38 +00:00
|
|
|
{
|
2023-12-11 18:59:13 +00:00
|
|
|
if (!string.IsNullOrEmpty(ConnectionString))
|
|
|
|
|
serviceBus.Host(ConnectionString);
|
|
|
|
|
|
|
|
|
|
ConfigureServiceBus?.Invoke(serviceBus);
|
|
|
|
|
|
|
|
|
|
serviceBus.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("Elsa", false));
|
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
|
|
|
}
|