Hangfire中AutomaticRetryAttribute过滤器的配置位置咨询
Great question! Let's break this down clearly:
You must configure this global retry filter in the client application that enqueues jobs — this is the critical piece. Here's why:
When Hangfire adds a job to the queue, it serializes the global filter settings (like your Attempts = 3) into the job's metadata. The server processing the job will read this metadata when executing the task, meaning the retry behavior is locked in at the moment the job is enqueued, not when it runs.
In short: If you set the global filter on the client, every job sent from that client will have the 3-retry rule baked in, no matter what configuration the processing server uses.
That said, it's also a smart practice to add the same configuration to your job-processing server as a fallback. This covers edge cases where jobs might be enqueued from other clients that don't have the retry filter set up — the server's global filter will provide a default retry policy for those tasks.
A couple of extra notes to round this out:
- If you need per-job retry overrides, just decorate the specific job method with
[AutomaticRetry(Attempts = 5)](or whatever number you need) — this takes priority over the global filter. - The code snippet you're using works perfectly for both client and server:
Place this in your client's startup logic (likeGlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 });Program.csin an ASP.NET Core app) and your server's startup code.
内容的提问来源于stack exchange,提问作者D.R.

