2023-01-01 17:02:38 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
|
|
|
|
using Elsa.MassTransit.Options;
|
|
|
|
|
using MassTransit;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.MassTransit.Features;
|
|
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Configures MassTransit to use the RabbitMQ broker.
|
|
|
|
|
/// </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
|
|
|
/// <summary>
|
|
|
|
|
/// A RabbitMQ connection string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Uri? ConnectionString { get; set; }
|
2023-01-01 17:02:38 +00:00
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// RabbitMQ options.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RabbitMqOptions? Options { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2023-01-01 17:02:38 +00:00
|
|
|
public override void Configure()
|
|
|
|
|
{
|
|
|
|
|
Module.Configure<MassTransitFeature>().BusConfigurator = configure =>
|
|
|
|
|
{
|
|
|
|
|
configure.UsingRabbitMq((context, configurator) =>
|
|
|
|
|
{
|
2023-01-04 14:28:28 +00:00
|
|
|
if (ConnectionString != null)
|
|
|
|
|
{
|
|
|
|
|
configurator.Host(ConnectionString);
|
|
|
|
|
}
|
|
|
|
|
else if (Options != null)
|
2023-01-01 17:02:38 +00:00
|
|
|
{
|
2023-01-04 14:28:28 +00:00
|
|
|
configurator.Host(Options.Host, h =>
|
|
|
|
|
{
|
|
|
|
|
h.Username(Options.Username);
|
|
|
|
|
h.Password(Options.Password);
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-01-01 17:02:38 +00:00
|
|
|
|
2023-01-04 19:36:38 +00:00
|
|
|
configurator.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("Elsa", false));
|
2023-01-01 17:02:38 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|