From b490e202fab720b578ed20cc4209de7ab7f6986e Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 10 Mar 2025 08:47:47 +0800 Subject: [PATCH 1/2] Add documentation for configuring background jobs and workers with multiple applications --- .../infrastructure/background-jobs/index.md | 73 ++++++++++++++++++ .../background-workers/index.md | 74 +++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/docs/en/framework/infrastructure/background-jobs/index.md b/docs/en/framework/infrastructure/background-jobs/index.md index 35f761ddf1..eb55107bec 100644 --- a/docs/en/framework/infrastructure/background-jobs/index.md +++ b/docs/en/framework/infrastructure/background-jobs/index.md @@ -236,6 +236,79 @@ Background Jobs module implements `IBackgroundJobStore` using various data acces > Background Jobs module is already installed to the startup templates by default and it works based on your ORM/data access choice. +### Multiple Applications Use Same Storage + +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/Workers + +Set `ApplicationName` of `AbpBackgroundJobWorkerOptions` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + PreConfigure(options => + { + options.ApplicationName = context.Services.GetApplicationName()!; + }); +} +```` + +#### Hangfire Background Job/Workers + +Set `DefaultQueuePrefix` of `AbpHangfireOptions` to your application name. + +````csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + Configure(options => + { + options.DefaultQueuePrefix = context.Services.GetApplicationName()!; + }); +} +```` + +#### Quartz Background Job/Workers + +Set `quartz.scheduler.instanceName` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + var configuration = context.Services.GetConfiguration(); + PreConfigure(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", + }; + }); +} +```` + +#### RabbitMQ Background Job + +Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` of `AbpRabbitMqBackgroundJobOptions` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + PreConfigure(options => + { + options.DefaultQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultQueueNamePrefix; + options.DefaultDelayedQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultDelayedQueueNamePrefix; + }); +} +```` + ### Clustered Deployment The default background job manager is compatible with [clustered environments](../../../deployment/clustered-environment.md) (where multiple instances of your application run concurrently). It uses a [distributed lock](../distributed-locking.md) to ensure that the jobs are executed only in a single application instance at a time. diff --git a/docs/en/framework/infrastructure/background-workers/index.md b/docs/en/framework/infrastructure/background-workers/index.md index 9f5d15e114..9d87ee7f84 100644 --- a/docs/en/framework/infrastructure/background-workers/index.md +++ b/docs/en/framework/infrastructure/background-workers/index.md @@ -132,6 +132,80 @@ If that's a problem for your workers, you have the following options: * Stop the background workers (set `AbpBackgroundWorkerOptions.IsEnabled` to `false`) in all application instances except one of them, so only the single instance runs the workers. * Stop the background workers (set `AbpBackgroundWorkerOptions.IsEnabled` to `false`) in all application instances and create a dedicated application (maybe a console application running in its own container or a Windows Service running in the background) to execute all the background tasks. This can be a good option if your background workers consume high system resources (CPU, RAM or Disk), so you can deploy that background application to a dedicated server and your background tasks don't affect your application's performance. + +### Multiple Applications Use Same Storage + +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/Workers + +Set `ApplicationName` of `AbpBackgroundJobWorkerOptions` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + PreConfigure(options => + { + options.ApplicationName = context.Services.GetApplicationName()!; + }); +} +```` + +#### Hangfire Background Job/Workers + +Set `DefaultQueuePrefix` of `AbpHangfireOptions` to your application name. + +````csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + Configure(options => + { + options.DefaultQueuePrefix = context.Services.GetApplicationName()!; + }); +} +```` + +#### Quartz Background Job/Workers + +Set `quartz.scheduler.instanceName` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + var configuration = context.Services.GetConfiguration(); + PreConfigure(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", + }; + }); +} +```` + +#### RabbitMQ Background Job + +Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` of `AbpRabbitMqBackgroundJobOptions` to your application name. + +````csharp +public override void PreConfigureServices(ServiceConfigurationContext context) +{ + PreConfigure(options => + { + options.DefaultQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultQueueNamePrefix; + options.DefaultDelayedQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultDelayedQueueNamePrefix; + }); +} +```` + ## Integrations Background worker system is extensible and you can change the default background worker manager with your own implementation or on of the pre-built integrations. From dd8cb9a053bcb9ca322d39479e96ba104b7f0e20 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Mon, 10 Mar 2025 10:02:40 +0300 Subject: [PATCH 2/2] Improve same-storage section in background jobs&workers docs --- .../infrastructure/background-jobs/index.md | 12 ++++++------ .../infrastructure/background-workers/index.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/en/framework/infrastructure/background-jobs/index.md b/docs/en/framework/infrastructure/background-jobs/index.md index eb55107bec..5aa58a7d3e 100644 --- a/docs/en/framework/infrastructure/background-jobs/index.md +++ b/docs/en/framework/infrastructure/background-jobs/index.md @@ -236,13 +236,13 @@ Background Jobs module implements `IBackgroundJobStore` using various data acces > Background Jobs module is already installed to the startup templates by default and it works based on your ORM/data access choice. -### Multiple Applications Use Same Storage +### Using the Same Storage for Background Jobs & Workers -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. +If multiple applications share the same storage for background jobs and workers (`Default, Hangfire, RabbitMQ, and Quartz`), you should configure the provider options to use the application name for isolation. #### Default Background Job/Workers -Set `ApplicationName` of `AbpBackgroundJobWorkerOptions` to your application name. +Set `ApplicationName` property in `AbpBackgroundJobWorkerOptions` to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context) @@ -256,7 +256,7 @@ public override void PreConfigureServices(ServiceConfigurationContext context) #### Hangfire Background Job/Workers -Set `DefaultQueuePrefix` of `AbpHangfireOptions` to your application name. +Set `DefaultQueuePrefix` property in `AbpHangfireOptions` to your application's name: ````csharp public override void ConfigureServices(ServiceConfigurationContext context) @@ -270,7 +270,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) #### Quartz Background Job/Workers -Set `quartz.scheduler.instanceName` to your application name. +Set the `quartz.scheduler.instanceName` property to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context) @@ -296,7 +296,7 @@ public override void PreConfigureServices(ServiceConfigurationContext context) #### RabbitMQ Background Job -Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` of `AbpRabbitMqBackgroundJobOptions` to your application name. +Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` properties in `AbpRabbitMqBackgroundJobOptions` to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context) diff --git a/docs/en/framework/infrastructure/background-workers/index.md b/docs/en/framework/infrastructure/background-workers/index.md index 9d87ee7f84..884ea60c25 100644 --- a/docs/en/framework/infrastructure/background-workers/index.md +++ b/docs/en/framework/infrastructure/background-workers/index.md @@ -133,13 +133,13 @@ If that's a problem for your workers, you have the following options: * Stop the background workers (set `AbpBackgroundWorkerOptions.IsEnabled` to `false`) in all application instances and create a dedicated application (maybe a console application running in its own container or a Windows Service running in the background) to execute all the background tasks. This can be a good option if your background workers consume high system resources (CPU, RAM or Disk), so you can deploy that background application to a dedicated server and your background tasks don't affect your application's performance. -### Multiple Applications Use Same Storage +### Using the Same Storage for Background Jobs & Workers -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. +If multiple applications share the same storage for background jobs and workers (`Default, Hangfire, RabbitMQ, and Quartz`), you should configure the provider options to use the application name for isolation. #### Default Background Job/Workers -Set `ApplicationName` of `AbpBackgroundJobWorkerOptions` to your application name. +Set `ApplicationName` property in `AbpBackgroundJobWorkerOptions` to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context) @@ -153,7 +153,7 @@ public override void PreConfigureServices(ServiceConfigurationContext context) #### Hangfire Background Job/Workers -Set `DefaultQueuePrefix` of `AbpHangfireOptions` to your application name. +Set `DefaultQueuePrefix` property in `AbpHangfireOptions` to your application's name: ````csharp public override void ConfigureServices(ServiceConfigurationContext context) @@ -167,7 +167,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) #### Quartz Background Job/Workers -Set `quartz.scheduler.instanceName` to your application name. +Set `quartz.scheduler.instanceName` property to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context) @@ -193,7 +193,7 @@ public override void PreConfigureServices(ServiceConfigurationContext context) #### RabbitMQ Background Job -Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` of `AbpRabbitMqBackgroundJobOptions` to your application name. +Set `DefaultQueueNamePrefix` and `DefaultDelayedQueueNamePrefix` properties in `AbpRabbitMqBackgroundJobOptions` to your application's name: ````csharp public override void PreConfigureServices(ServiceConfigurationContext context)