Merge pull request #1 from CODEdire/masstransit-addcontext
Added minor changes to MassTransitFeature to start using MassTransitOptions as the source for the prefetch count as the new source for this information is in the base MassTransitOptions. Created a new ConfigureTransportBus in both RabbitMQ and Azure Service Bus to support the context in the configuration action. Marked the old ConfigureServiceBus to persuade migration over to the contextual action. Currently, it will run the legacy action first and then the new contextual action second. The Elsa.Server.Web was also updated to use the new ConfigureTransportBus.
This commit is contained in:
commit
51aa94be45
|
|
@ -481,7 +481,7 @@ services
|
|||
|
||||
if (massTransitBroker == MassTransitBroker.AzureServiceBus)
|
||||
{
|
||||
massTransit.UseAzureServiceBus(azureServiceBusConnectionString, serviceBusFeature => serviceBusFeature.ConfigureServiceBus = bus =>
|
||||
massTransit.UseAzureServiceBus(azureServiceBusConnectionString, serviceBusFeature => serviceBusFeature.ConfigureTransportBus = (context, bus) =>
|
||||
{
|
||||
bus.PrefetchCount = 50;
|
||||
bus.LockDuration = TimeSpan.FromMinutes(5);
|
||||
|
|
@ -493,7 +493,7 @@ services
|
|||
|
||||
if (massTransitBroker == MassTransitBroker.RabbitMq)
|
||||
{
|
||||
massTransit.UseRabbitMq(rabbitMqConnectionString, rabbit => rabbit.ConfigureServiceBus = bus =>
|
||||
massTransit.UseRabbitMq(rabbitMqConnectionString, rabbit => rabbit.ConfigureTransportBus = (context, bus) =>
|
||||
{
|
||||
bus.PrefetchCount = 50;
|
||||
bus.Durable = true;
|
||||
|
|
|
|||
|
|
@ -53,8 +53,20 @@ public class AzureServiceBusFeature : FeatureBase
|
|||
/// <summary>
|
||||
/// A delegate that configures the Azure Service Bus transport options.
|
||||
/// </summary>
|
||||
/// <remarks>This method is being marked as obsolete in favor of the ConfigureTransportBus which will provide additional access to the <see cref="IBusRegistrationContext"/></remarks>
|
||||
[Obsolete("Use ConfigureTransportBus instead which provides a reference to IBusRegistrationContext.")]
|
||||
public Action<IServiceBusBusFactoryConfigurator>? ConfigureServiceBus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configures the Azure Service Bus within MassTransit for additional transport level components or features.
|
||||
/// This action provides access to the <see cref="IBusRegistrationContext"/> and <see cref="IServiceBusBusFactoryConfigurator"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this action to configure advanced settings and features for the Azure Service Bus, such as middleware
|
||||
/// or additional endpoints. This action will run in addition to the Elsa required configuration.
|
||||
/// </remarks>
|
||||
public Action<IBusRegistrationContext, IServiceBusBusFactoryConfigurator> ConfigureTransportBus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A delegate to configure <see cref="AzureServiceBusOptions"/>.
|
||||
/// </summary>
|
||||
|
|
@ -104,6 +116,7 @@ public class AzureServiceBusFeature : FeatureBase
|
|||
|
||||
configurator.UseServiceBusMessageScheduler();
|
||||
ConfigureServiceBus?.Invoke(configurator);
|
||||
ConfigureTransportBus?.Invoke(context, configurator);
|
||||
var instanceNameProvider = context.GetRequiredService<IApplicationInstanceNameProvider>();
|
||||
|
||||
foreach (var consumer in temporaryConsumers)
|
||||
|
|
|
|||
|
|
@ -39,8 +39,20 @@ public class RabbitMqServiceBusFeature : FeatureBase
|
|||
/// <summary>
|
||||
/// Configures the RabbitMQ bus.
|
||||
/// </summary>
|
||||
/// <remarks>This method is being marked as obsolete in favor of the ConfigureTransportBus which will provide additional access to the <see cref="IBusRegistrationContext"/></remarks>
|
||||
[Obsolete("Use ConfigureTransportBus instead which provides a reference to IBusRegistrationContext.")]
|
||||
public Action<IRabbitMqBusFactoryConfigurator>? ConfigureServiceBus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configures the RabbitMQ bus within MassTransit for additional transport level components or features.
|
||||
/// This action provides access to the <see cref="IBusRegistrationContext"/> and <see cref="IRabbitMqBusFactoryConfigurator"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this action to configure advanced settings and features for the RabbitMQ bus, such as middleware
|
||||
/// or additional endpoints. This action will run in addition to the Elsa required configuration.
|
||||
/// </remarks>
|
||||
public Action<IBusRegistrationContext, IRabbitMqBusFactoryConfigurator> ConfigureTransportBus { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Configure()
|
||||
{
|
||||
|
|
@ -69,6 +81,7 @@ public class RabbitMqServiceBusFeature : FeatureBase
|
|||
configurator.ConcurrentMessageLimit = options.ConcurrentMessageLimit;
|
||||
|
||||
ConfigureServiceBus?.Invoke(configurator);
|
||||
ConfigureTransportBus?.Invoke(context, configurator);
|
||||
|
||||
foreach (var consumer in temporaryConsumers)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public class MassTransitFeature : FeatureBase
|
|||
/// <summary>
|
||||
/// Adds MassTransit to the service container and registers all collected assemblies for discovery of consumers.
|
||||
/// </summary>
|
||||
/// <param name="busConfigurator">The bus configurator used to configure the MassTransit Bus.</param>
|
||||
private void AddMassTransit(Action<IBusRegistrationConfigurator> busConfigurator)
|
||||
{
|
||||
// For each message type, create a concrete WorkflowMessageConsumer<T>.
|
||||
|
|
@ -119,6 +120,10 @@ public class MassTransitFeature : FeatureBase
|
|||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures MassTransit to use the in-memory transport when no other transport has been configured.
|
||||
/// </summary>
|
||||
/// <param name="configure"><see cref="IBusRegistrationConfigurator"/> reference to the MassTransit bus to configure for and in-memory transport</param>
|
||||
private void ConfigureInMemoryTransport(IBusRegistrationConfigurator configure)
|
||||
{
|
||||
var consumers = this.GetConsumers().ToList();
|
||||
|
|
@ -131,6 +136,7 @@ public class MassTransitFeature : FeatureBase
|
|||
configure.UsingInMemory((context, bus) =>
|
||||
{
|
||||
var options = context.GetRequiredService<IOptions<MassTransitWorkflowDispatcherOptions>>().Value;
|
||||
var busOptions = context.GetRequiredService<IOptions<MassTransitOptions>>().Value;
|
||||
|
||||
foreach (var consumer in temporaryConsumers)
|
||||
{
|
||||
|
|
@ -156,7 +162,7 @@ public class MassTransitFeature : FeatureBase
|
|||
return serializerOptions;
|
||||
});
|
||||
|
||||
if (PrefetchCount != null) bus.PrefetchCount = PrefetchCount.Value;
|
||||
if (busOptions.PrefetchCount.HasValue) bus.PrefetchCount = busOptions.PrefetchCount.Value;
|
||||
|
||||
bus.ConfigureTenantMiddleware(context);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue