Hangfire
Reference · Applies to Brighter V10
Hangfire is one of the most widely used background job processing libraries in the .NET community, featuring a built-in monitoring dashboard. Brighter provides first-class integration with Hangfire for scheduler functionality, making it an excellent choice for production systems requiring easy setup, visual monitoring, and persistent scheduling.
Production Recommendation
Hangfire is highly recommended for production use alongside Quartz.NET as one of the two primary production schedulers for Brighter.
Why Choose Hangfire?
✅ Built-in Dashboard: Web UI for monitoring jobs, queues, and servers
✅ Easy Setup: Simple configuration and minimal boilerplate
✅ Persistent: Jobs stored in databases (SQL Server, PostgreSQL, Redis, etc.)
✅ Reliable: Jobs survive application restarts and crashes
✅ Cancellation: Full support for cancelling scheduled jobs
✅ Automatic Retries: Configurable retry policies for failed jobs
✅ Multiple Storage: SQL Server, PostgreSQL, MySQL, Redis, MongoDB
✅ Background Processing: Beyond scheduling - fire-and-forget, delayed, recurring jobs
⚠️ Important: Strong Naming Limitation
The Paramore.Brighter.MessageScheduler.Hangfire assembly is NOT strong-named.
This is due to Hangfire itself not using strong naming. If your application requires all assemblies to be strong-named (for example, for enterprise policy compliance), you will need to use an alternative scheduler (Quartz.NET or AWS/Azure schedulers).
Why this matters:
Cannot mix strong-named and non-strong-named assemblies in some enterprise environments
May cause issues with certain security policies
Use Quartz.NET if strong naming is a hard requirement
Hangfire Overview
Hangfire is a comprehensive background job processing library that provides:
Persistent Job Storage: Store jobs in various backends
Automatic Retry: Retry failed jobs with exponential backoff
Dashboard: Web-based monitoring UI
Multiple Queue Support: Organize jobs into different queues
Job Continuations: Chain jobs together
Recurring Jobs: Cron-based scheduling
Job Filters: Intercept job execution
Distributed Processing: Multiple servers can process jobs
For more information, visit the Hangfire documentation.
How Brighter Integrates with Hangfire
Brighter integrates with Hangfire through:
BrighterHangfireSchedulerJob: A Hangfire job that executes scheduled Brighter messages
HangfireMessageSchedulerFactory: Factory that creates Brighter's message scheduler backed by Hangfire
JobActivator Integration: Uses Brighter's DI container to resolve jobs
When you schedule a message with Brighter:
Brighter creates a Hangfire background job with the message payload
Hangfire persists the job to its storage backend
At the scheduled time, Hangfire fires the job
BrighterHangfireSchedulerJob receives the job execution
BrighterHangfireSchedulerJob dispatches the message via Brighter's Command Processor
Your handler executes
Job appears in Hangfire dashboard with status
Hangfire NuGet Packages
Install the required NuGet packages:
For persistence, add a Hangfire storage package:
Hangfire Configuration
Hangfire Scheduler Factory Options
HangfireMessageSchedulerFactory takes no constructor arguments and exposes three properties. Storage, retries, the dashboard and the worker count all belong to Hangfire itself and are configured through AddHangfire, not here.
Queue
string?
null
Names the Hangfire queue scheduled jobs are enqueued on; Hangfire uses its default queue when this is null.
Client
IBackgroundJobClientV2
a new BackgroundJobClient
The Hangfire client the scheduler enqueues jobs through.
TimeProvider
TimeProvider
TimeProvider.System
The clock the scheduler measures delays against.
Client is created eagerly, so configure Hangfire before you construct the factory. Its initialiser calls new BackgroundJobClient(), which reads Hangfire's JobStorage.Current static and throws InvalidOperationException: Current JobStorage instance has not been initialized yet when no storage is registered. Register your Hangfire storage before the factory is constructed, as the complete examples below do.
Basic Configuration
Configure Brighter with Hangfire scheduler:
Configuration with PostgreSQL
Configuration with Redis
Configuration with Custom Queue
Organize Brighter jobs into a specific queue:
Benefits:
Isolate Brighter jobs from other Hangfire jobs
Configure different server instances for different queues
Monitor Brighter jobs separately in dashboard
Storage Options
Hangfire supports multiple persistent storage backends:
SQL Server
PostgreSQL
MySQL
Redis
In-Memory (Development Only)
⚠️ Warning: In-memory storage loses all jobs on restart. Use persistent storage for production.
Dashboard
Hangfire includes a powerful web-based dashboard for monitoring jobs.
Basic Dashboard Setup
Dashboard with Authentication
Secure the dashboard with authorization:
Dashboard with Custom Path and Options
Dashboard Features
The Hangfire dashboard provides:
Jobs: View all jobs (scheduled, processing, succeeded, failed)
Retries: Monitor automatic retry attempts
Recurring Jobs: Manage recurring jobs
Servers: View active Hangfire servers
Succeeded/Failed: Historical job execution data
Real-time Updates: Live job status updates
Job Details: Inspect job arguments and exceptions
Manual Actions: Requeue, delete, or retry jobs
Hangfire Code Examples
Basic Scheduling
Cancelling a Scheduled Job
Scheduling with Absolute Time
High Availability with Multiple Servers
Hangfire supports multiple server instances for high availability:
How HA works:
Multiple servers connect to the same storage backend
Jobs are distributed among active servers
If a server fails, other servers take over its jobs
Each server processes jobs independently
Dashboard shows all servers and their status
Best practices for HA:
Use shared persistent storage (SQL Server, PostgreSQL, etc.)
Configure unique server names
Monitor server health in dashboard
Set appropriate worker counts per server
Use queues to control job distribution
Hangfire Monitoring and Observability
Job Filters
Monitor job execution with filters:
Health Checks
Monitor Hangfire health:
Hangfire Best Practices
1. Always Use Persistent Storage in Production
2. Secure the Dashboard
3. Use Custom Queues for Organization
4. Store Scheduler IDs for Cancellation
5. Configure Appropriate Worker Counts
6. Monitor the Dashboard Regularly
7. Handle Timezone Correctly
8. Configure Automatic Retry Policies
Hangfire Troubleshooting
Jobs Not Executing
Symptom: Jobs scheduled but never execute
Possible Causes:
Hangfire server not started
Database connectivity issues
BrighterHangfireSchedulerJob not registered
No workers processing the queue
Solutions:
Jobs Executing Multiple Times
Symptom: Same job executes multiple times
Cause: Multiple servers or configuration issues
Solution:
Dashboard Not Loading
Symptom: Dashboard URL returns 404
Possible Causes:
Dashboard not registered
Incorrect URL path
Authentication blocking access
Solutions:
Related Documentation
Brighter Scheduler Support - Overview of scheduling in Brighter
Switching Schedulers - Moving to or from this scheduler
InMemory Scheduler - Lightweight scheduler for testing
Quartz Scheduler - Alternative production scheduler with strong naming
AWS Scheduler - Cloud-native AWS scheduling
Azure Scheduler - Cloud-native Azure scheduling
Hangfire Documentation - Official Hangfire documentation
Hangfire Summary
Hangfire is an excellent production scheduler for Brighter offering:
✅ Dashboard: Built-in web UI for monitoring and management
✅ Easy Setup: Minimal configuration required
✅ Persistent: Jobs survive restarts with multiple storage options
✅ Reliable: Automatic retries and distributed processing
✅ Visual Monitoring: Real-time job status and history
⚠️ Strong Naming: NOT strong-named (use Quartz if required)
Use Hangfire when you need a production scheduler with a built-in dashboard and easy setup. If strong naming is required, use Quartz.NET instead.
Last updated
Was this helpful?
