Skip to content

MaintenanceMode

blehnen edited this page Mar 30, 2026 · 3 revisions

Maintenance Mode

By default, each consumer runs its own maintenance monitors (heartbeat reset, message expiration cleanup, error cleanup). The MaintenanceMode setting lets you run these monitors separately from the consumer.

Configuration

Set MaintenanceMode on the consumer configuration:

queue.Configuration.MaintenanceMode = MaintenanceMode.External;
Value Behavior
Consumer (default) Each consumer runs its own maintenance monitors
External Consumer skips maintenance monitors; they must run elsewhere

Per-message heartbeat updates are unaffected by this setting. Consumers always update heartbeats for messages they are actively processing, regardless of mode.

Running maintenance externally

Use IQueueMaintenanceService to run maintenance outside the consumer. This is registered in the queue container and can be resolved directly:

var maintenanceService = container.GetInstance<IQueueMaintenanceService>();
maintenanceService.Start();

// Check status
Console.WriteLine($"Running: {maintenanceService.IsRunning}");
Console.WriteLine($"Last run: {maintenanceService.LastRun}");

// Stop when done
maintenanceService.Stop();
Dashboard-hosted maintenance

The Dashboard API can host maintenance on behalf of your queues. Set HostMaintenance = true on the queue options:

builder.Services.AddDotNetWorkQueueDashboard(options =>
{
    options.AddConnection<SqlServerMessageQueueInit>(connectionString, conn =>
    {
        conn.DisplayName = "Production";
        conn.AddQueue("OrderQueue", hostMaintenance: true);
    });
});

When enabled, the dashboard starts maintenance monitors for the queue at startup and exposes status via GET /api/v1/dashboard/queues/{queueId}/maintenance.

The corresponding consumers should set MaintenanceMode = External to avoid duplicate work.

When to use external maintenance
  • When running many consumer instances and you want to reduce redundant maintenance work
  • When you want centralized control over maintenance scheduling
  • When using the Dashboard API and want a single place to manage queue health

Clone this wiki locally