arcus-azure/arcus.backgroundjobs

Order of `AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob` registration matters

Closed this issue · 2 comments

Describe the bug
When registering a background job to automatically restart a related Azure Service Bus message pump based on rotated credentials, it matters when the job is registered, while this should not matter.

To Reproduce
Register the background job before the message pump. The functionality only works when the message pump is registered first.

Expected behavior
Order doesn't matter.

Additional context
Current version v0.3.0.

This has something to do with the selection of the Azure Service Bus message pump based on its job ID. We should look into how the IServiceProvider is called and whether we still have the 'most recent' registered services.

This can be changed by adding an dedicated extension on the ServiceBusMessageHandlerCollection, so we both fixes this issue and makes the user-experience of adding this kind of background.

services.AddServiceBusQueueMessagePump(KeyVaultSecretName, opt => opt.JobId = JobId)
        .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>()
        .WithAutoRestartOnRotatedCredentials(jobId, ...);

Instead of the now dedicated service collection extension:

services.AddServiceBusQueueMessagePump(KeyVaultSecretName, opt => opt.JobId = JobId)
        .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>();

services.AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob(jobId, ...);

If we in a later version update the ServiceBusMessageHandlerCollection in Arcus Messaging with a JobId property, we don't even have to pass this in.