Skip to content

DashboardClient

blehnen edited this page Mar 30, 2026 · 3 revisions

Dashboard Client

DotNetWorkQueue.Dashboard.Client is a standalone NuGet package with a typed C# client for the Dashboard API. It has no dependency on the core DotNetWorkQueue library; it talks to the API over HTTP using System.Text.Json.

Installation
Install-Package DotNetWorkQueue.Dashboard.Client
DashboardApiClient

Typed wrapper around all Dashboard API endpoints. Methods return ApiReturnValue<T> with Success, StatusCode, ErrorMessage, and Value properties instead of throwing on non-2xx responses.

var options = new DashboardClientOptions
{
    DashboardApiUrl = "https://localhost:5001",
    ApiKey = "my-secret-key" // optional
};

using var client = new DashboardApiClient(options);

// List connections
var connections = await client.GetConnectionsAsync();
if (connections.Success)
{
    foreach (var conn in connections.Value)
        Console.WriteLine($"{conn.DisplayName}: {conn.QueueCount} queues");
}

// Get queue status
var status = await client.GetQueueStatusAsync(queueId);
Console.WriteLine($"Waiting: {status.Value.Waiting}, Errors: {status.Value.Error}");

// Page through messages
var messages = await client.GetMessagesAsync(queueId, pageIndex: 0, pageSize: 50, status: 0);

// Requeue all errors
var result = await client.RequeueAllErrorsAsync(queueId);
Console.WriteLine($"Requeued: {result.Value.Count}");

The client can also be created with an HttpClient or IHttpClientFactory for dependency injection scenarios:

// With IHttpClientFactory
services.AddHttpClient("DashboardApi", client =>
{
    client.BaseAddress = new Uri("https://localhost:5001/");
});

var client = new DashboardApiClient(httpClientFactory, options);
DashboardConsumerClient

Handles consumer registration, heartbeats, and unregistration with the Dashboard API. Use this in your consumer apps to enable consumer tracking in the dashboard.

var options = new DashboardClientOptions
{
    DashboardApiUrl = "https://localhost:5001",
    QueueName = "OrderQueue",
    FriendlyName = "Worker-1"
};

using var consumer = new DashboardConsumerClient(options);
await consumer.StartAsync(); // registers and starts heartbeat timer

Console.WriteLine($"Registered as: {consumer.ConsumerId}");

// ... process messages ...
// heartbeat runs automatically in the background

await consumer.StopAsync(); // stops heartbeat and unregisters

Key behaviors:

  • StartAsync() registers the consumer and starts a background heartbeat timer at the interval specified by the server (default 30 seconds)
  • If heartbeats fail and the server prunes the consumer, the client detects the 404 and clears its registration
  • StopAsync() and Dispose() attempt to unregister but swallow failures (best-effort)
  • StartAsync() is idempotent — calling it multiple times only registers once
DashboardClientOptions
Property Required Description
DashboardApiUrl Yes Base URL of the Dashboard API
ApiKey No API key sent as X-Api-Key header
QueueName For consumer Queue name for consumer registration
FriendlyName No Display name for this consumer instance

Clone this wiki locally