refactor(infra): auto-configure MassTransit endpoints via ConfigureEndpoints
Replace ~240 lines of hand-written per-endpoint wiring with MassTransit's ConfigureEndpoints + KebabCaseEndpointNameFormatter, and apply retry + EF outbox globally through AddConfigureEndpointsCallback. Adding a consumer or activity is now a single AddConsumer/AddActivity line. - Normalize the 4 mismatched activity endpoint names to kebab-case so the routing-slip addressing keeps resolving (update-play-list-picture, delete/mark/publish play-list variants); cleanup consumer queue is now routing-slip-clean-up - Drop the now-unused QueueName consts from event consumers and trim EndpointHelper / delete the manual endpoint-config partial Verified end-to-end: booted the Worker against RabbitMQ in Docker and confirmed all 38 endpoints are configured with the exact names the builders address (19 execute queues + compensations + consumers + routing-slip-clean-up). Build: 0 warnings, 0 errors.
This commit is contained in:
+23
-1
@@ -62,15 +62,37 @@ namespace Musify.Infrastructure.MassTransit
|
||||
outbox.DuplicateDetectionWindow = TimeSpan.FromMinutes(30);
|
||||
});
|
||||
|
||||
options.SetKebabCaseEndpointNameFormatter();
|
||||
|
||||
RegisterConsumersAndActivities(options);
|
||||
|
||||
options.AddConfigureEndpointsCallback((registrationContext, _, endpointConfigurator) =>
|
||||
{
|
||||
UseStandardRetry(endpointConfigurator);
|
||||
endpointConfigurator.UseEntityFrameworkOutbox<Database>(registrationContext);
|
||||
});
|
||||
|
||||
options.UsingRabbitMq((busRegistrationContext, busFactoryConfigurator) =>
|
||||
ConfigureRabbitMqWorkerEndpoints(busRegistrationContext, busFactoryConfigurator));
|
||||
{
|
||||
ConfigureRabbitMqHost(
|
||||
busFactoryConfigurator,
|
||||
busRegistrationContext.GetRequiredService<MassTransitConfiguration>());
|
||||
|
||||
busFactoryConfigurator.ConfigureEndpoints(busRegistrationContext);
|
||||
});
|
||||
} );
|
||||
|
||||
return serviceDescriptors;
|
||||
}
|
||||
|
||||
static void UseStandardRetry(IReceiveEndpointConfigurator endpointConfigurator) =>
|
||||
endpointConfigurator.UseMessageRetry(retryConfigurator =>
|
||||
retryConfigurator.Exponential(
|
||||
retryLimit: 5,
|
||||
minInterval: TimeSpan.FromSeconds(1),
|
||||
maxInterval: TimeSpan.FromSeconds(30),
|
||||
intervalDelta: TimeSpan.FromSeconds(2)));
|
||||
|
||||
static void ConfigureRabbitMqHost(
|
||||
IRabbitMqBusFactoryConfigurator busFactoryConfigurator,
|
||||
MassTransitConfiguration massTransitConfiguration)
|
||||
|
||||
Reference in New Issue
Block a user