zhmdff.uc.Client
1.0.6
dotnet add package zhmdff.uc.Client --version 1.0.6
NuGet\Install-Package zhmdff.uc.Client -Version 1.0.6
<PackageReference Include="zhmdff.uc.Client" Version="1.0.6" />
<PackageVersion Include="zhmdff.uc.Client" Version="1.0.6" />
<PackageReference Include="zhmdff.uc.Client" />
paket add zhmdff.uc.Client --version 1.0.6
#r "nuget: zhmdff.uc.Client, 1.0.6"
#:package zhmdff.uc.Client@1.0.6
#addin nuget:?package=zhmdff.uc.Client&version=1.0.6
#tool nuget:?package=zhmdff.uc.Client&version=1.0.6
zhmdff.uc.Client
A fail-open .NET 8 client SDK for the zhmdffUC control-plane. Provides ASP.NET Core middleware, background polling, Serilog sink, and log transport with zero impact on your application's reliability during control-plane downtime.
Features
- Middleware: automatically short-circuits requests when your project status is
PausedorDisabled - Heartbeat Endpoint: Built-in
/_uc/statusendpoint to allow the control-plane to ping, wake up, and sync with your container. - Fail-Open: if the control-plane is unreachable and
FailOpen = true, all requests pass through - Background polling: dual
IHostedServiceloop — status poll + log flush. Supports ETag optimization to reduce bandwidth. - Log Transport: ships logs to the control-plane respecting per-project enabled log levels. Supports optional GZIP compression.
- Metadata & Profile Sync: Read and write project-specific private metadata (
UpdateMetadataAsync) and fetch centralized app profiles. - SDK registration: announces itself to the control-plane on startup (version, hostname, runtime)
- Dual-Key Auth Support: Supports both project-specific API keys and the global Master API Key for authentication.
Package Structure
zhmdff.uc.Client/
MasterControlExtensions.cs — AddMasterControl() + UseMasterControl()
MasterControlMiddleware.cs — ASP.NET Core middleware (with /_uc/status heartbeat + ETags)
MasterControlService.cs — IHostedService (status poll + log flush + ping loops)
ZhmdffUcClient.cs — On-demand polling client (Metadata, Status, Profile)
ZhmdffUcOptions.cs — Options class
IZhmdffUcClient.cs — Interface for mocking
Http/
MasterControlHttpClient.cs — Centralized HttpClient with ETags and GZIP support
Logging/ MasterControlSink.cs — Serilog ILogEventSink LogBuffer.cs — ConcurrentQueue<LogEntry> (max 1000, drop-oldest) Models/ ProjectStatus.cs LogBatch.cs SdkRegistration.cs DependencyInjection/ — Internal DI helpers Cache/ — IMemoryCache slot management
---
## Quick Start
### 1. Configure `appsettings.json`
```json
{
"MasterControl": {
"BaseUrl": "https://uc.zhmdff.dev",
"ProjectId": "your-project-guid",
"ApiKey": "your-project-api-key",
"PollIntervalSeconds": 30,
"LogFlushIntervalSeconds": 45,
"FailOpen": true,
"GzipLogs": false,
"GzipThreshold": 1024
}
}
2. Register in Program.cs
using zhmdff.uc.Client;
// Registers typed HttpClient, IHostedService, and Serilog sink
builder.Services.AddMasterControl(builder.Configuration);
// Optional: Serilog integration
builder.Host.UseSerilog((ctx, cfg) =>
cfg.WriteTo.Console()
.WriteTo.MasterControl());
var app = builder.Build();
// Must be first middleware in the pipeline
app.UseMasterControl();
3. Middleware Behaviour
On each request MasterControlMiddleware reads the cached ProjectStatus from IMemoryCache:
| Path | Behavior |
|---|---|
/_uc/status |
Returns 200 OK with cached status (Internal Heartbeat) |
| Any other path | Short-circuits if Paused/Disabled, otherwise calls next |
Response body for /_uc/status:
{
"projectId": "guid",
"status": "Active",
"statusCode": 200,
"isFromCache": true
}
Options Reference
| Option | Default | Description |
|---|---|---|
BaseUrl |
required | zhmdffUC backend URL |
ProjectId |
required | Project GUID |
ApiKey |
null |
Project API key (X-Project-Key header) |
PollIntervalSeconds |
30 |
How often to refresh status from the API |
LogFlushIntervalSeconds |
45 |
How often to flush LogBuffer to /api/logs/ingest |
FailOpen |
true |
Pass requests through when status is unknown |
Serilog Sink
MasterControlSink checks the EnabledLogLevels returned by the last status poll before enqueuing. Only matching log levels are buffered.
// Wired automatically by AddMasterControl() — or manually:
.WriteTo.MasterControl()
LogBuffer is a ConcurrentQueue<LogEntry> capped at 1,000 entries. Oldest entries are dropped on overflow.
Resilience Guarantees
| Scenario | Behavior |
|---|---|
| Backend offline | Last cached status served; FailOpen passes requests |
| Poll timeout / 5xx | Failure swallowed, cache unchanged |
| Startup (no cache yet) | FailOpen = true → pass through; false → block |
| Log flush failure | Buffer retained, retry on next interval |
Running Tests
cd Packages/nuget
dotnet test zhmdff.uc.Client.Tests\zhmdff.uc.Client.Tests.csproj --logger "console;verbosity=normal"
Current version: 1.0.6.
Part of the zhmdffUC ecosystem. See usage.md for full integration guide.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Serilog (>= 3.1.1)
- System.Net.Http.Json (>= 8.0.0)
- System.Text.Json (>= 8.0.4)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Serilog (>= 3.1.1)
- System.Net.Http.Json (>= 8.0.0)
- System.Text.Json (>= 8.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.