-
Notifications
You must be signed in to change notification settings - Fork 16
DashboardClient
blehnen edited this page Mar 30, 2026
·
3 revisions
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.
Install-Package DotNetWorkQueue.Dashboard.ClientTyped 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);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 unregistersKey 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()andDispose()attempt to unregister but swallow failures (best-effort) -
StartAsync()is idempotent — calling it multiple times only registers once
| 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 |
For any issues please use the GitHub issues