Skip to content
New issue

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

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

Already on GitHub? # to your account

Update hangfire.md #22192

Open
wants to merge 1 commit into
base: rel-8.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions docs/en/framework/infrastructure/background-jobs/hangfire.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,68 @@ namespace MyProject
}
````

### Specifying Queue Names

You can specify the queue for Hangfire jobs in two ways:

1. **Using `AddHangfireServer` Method**:

```csharp
context.Services.AddHangfireServer(options =>
{
options.Queues = new[] { "alpha" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

ABP does not support the method because ABP internally creates a HangfireServer.
https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireOptions.cs#L35

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, actually I guessed it already creates a HangifireServer but it worked also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI, after test, it not work. you can try use the demo app https://github.com/omer-repo/abp/tree/patch-2/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq
to configure the AddHangfireServer method:

You will find that it is still consuming the default queue

context.Services.AddHangfireServer(options =>
{
    options.Queues = new[] { "alpha" };
});

});
```

1. **Using `AbpHangfireOptions` **:

```csharp
Configure<AbpHangfireOptions>(options =>
{
options.ServerOptions = new BackgroundJobServerOptions()
{
Queues = new[] { "default", "alpha" }
};
});
```

You can add one of these configurations to the ConfigureHangfire method or after the ConfigureHangfire method in the ConfigureServices method.

Here is an example of how to add these configurations:
```csharp
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();

ConfigureHangfire(context, configuration);


}

private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddHangfire(config =>
{
config.UseSqlServerStorage(configuration.GetConnectionString("Default"));
});

// Option 1: Using AddHangfireServer
context.Services.AddHangfireServer(options =>
{
options.Queues = new[] { "alpha" };
});

// Option 2: Using AbpHangfireOptions
Configure<AbpHangfireOptions>(options =>
{
options.ServerOptions = new BackgroundJobServerOptions()
{
Queues = new[] { "default", "alpha" }
};
});
}
```

### Dashboard Authorization

Hangfire Dashboard provides information about your background jobs, including method names and serialized arguments as well as gives you an opportunity to manage them by performing different actions – retry, delete, trigger, etc. So it is important to restrict access to the Dashboard.
Expand Down