Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApplicationName property to isolate jobs/workers. #22169

Merged
merged 3 commits into from
Mar 8, 2025

Conversation

maliming
Copy link
Member

@maliming maliming commented Feb 17, 2025

Resolves #22081

No breaking changes are caused by default.

A breaking change label was added because the database migration needs to be added.

If you have multiple applications using one storage as background jobs and workers(Default, Hangfire, RabbitMQ, and Quartz), You should set the provider options to use the application name to isolate.

Default Background Job:

Set ApplicationName of AbpBackgroundJobWorkerOptions to your application name.

public override void PreConfigureServices(ServiceConfigurationContext context)
{
    PreConfigure<AbpBackgroundJobWorkerOptions>(options =>
    {
        options.ApplicationName = context.Services.GetApplicationName()!;
    });
}

Hangfire:

Set DefaultQueuePrefix of AbpHangfireOptions to your application name.

public override void ConfigureServices(ServiceConfigurationContext context)
{
    Configure<AbpHangfireOptions>(options =>
    {
        options.DefaultQueuePrefix = context.Services.GetApplicationName()!;
    });
}

RabbitMQ:

Set DefaultQueueNamePrefix and DefaultDelayedQueueNamePrefix of AbpRabbitMqBackgroundJobOptions to your application name.

public override void PreConfigureServices(ServiceConfigurationContext context)
{
    PreConfigure<AbpRabbitMqBackgroundJobOptions>(options =>
    {
        options.DefaultQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultQueueNamePrefix;
        options.DefaultDelayedQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultDelayedQueueNamePrefix;
    });
}

Quartz:

Set quartz.scheduler.instanceName to your application name.

public override void PreConfigureServices(ServiceConfigurationContext context)
{
    //https://github.com/quartznet/quartznet/blob/main/database/tables/tables_sqlServer.sql
    var configuration = context.Services.GetConfiguration();
    PreConfigure<AbpQuartzOptions>(options =>
    {
        options.Properties = new NameValueCollection
        {
            ["quartz.scheduler.instanceName"] = context.Services.GetApplicationName(),

            ["quartz.jobStore.dataSource"] = "BackgroundJobsDemoApp",
            ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
            ["quartz.jobStore.tablePrefix"] = "QRTZ_",
            ["quartz.serializer.type"] = "json",
            ["quartz.dataSource.BackgroundJobsDemoApp.connectionString"] = configuration.GetConnectionString("Default"),
            ["quartz.dataSource.BackgroundJobsDemoApp.provider"] = "SqlServer",
            ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz",
        };
    });
}

You can use this app to test: https://github.com/abpframework/abp/tree/BackgroundJob-ApplicationName-Test/modules/background-jobs/app


If there is no problem, I will update the document later.

@maliming maliming added this to the 9.2-preview milestone Feb 17, 2025
@maliming maliming force-pushed the BackgroundJob-ApplicationName branch from f0323d9 to 382a71d Compare February 18, 2025 09:42
@maliming maliming marked this pull request as ready for review February 19, 2025 05:53
@maliming maliming marked this pull request as draft February 19, 2025 07:19
@maliming maliming marked this pull request as ready for review February 19, 2025 09:26
@maliming maliming requested a review from salihozkara February 21, 2025 13:48
@maliming maliming force-pushed the BackgroundJob-ApplicationName branch from ca6f255 to a463b97 Compare February 22, 2025 09:59
@maliming maliming changed the title Add ApplicationName property to background job classes and options for isolation. dd ApplicationName property to background job to isolate jobs. Feb 22, 2025
@maliming maliming changed the title dd ApplicationName property to background job to isolate jobs. Add ApplicationName property to background job to isolate jobs. Feb 22, 2025
@maliming maliming changed the title Add ApplicationName property to background job to isolate jobs. Add ApplicationName property to background job to isolate jobs/workers. Feb 22, 2025
@maliming maliming changed the title Add ApplicationName property to background job to isolate jobs/workers. Add ApplicationName property to isolate jobs/workers. Feb 22, 2025
@hikalkan hikalkan merged commit ec70d0c into dev Mar 8, 2025
3 checks passed
@hikalkan hikalkan deleted the BackgroundJob-ApplicationName branch March 8, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ABP BackgroundJobs Module - Issue with Processing Jobs Across Multiple Applications
4 participants