.NET Aspire
Provision KubeMQ and configure IKubeMQClient in .NET Aspire apps with health checks, OpenTelemetry, and keyed DI.
The KubeMQ .NET Aspire integration wires the KubeMQ message broker into the .NET Aspire application model. It follows the standard Aspire two-package model: KubeMQ.Aspire.Hosting provisions a KubeMQ container in your AppHost, and KubeMQ.Aspire.Client configures an IKubeMQClient in each consuming service — complete with health checks, OpenTelemetry, and keyed dependency injection. The client is a native gRPC SDK client that connects to the broker on port 50000; there is no connector to enable.
New to the idea? See what is an integration for how SDK-level integrations differ from server-side connectors.
Why KubeMQ + .NET Aspire?
- Container auto-provisioning —
AddKubeMQ("messaging")in the AppHost runs a KubeMQ broker container with the gRPC, REST, and Dashboard endpoints already mapped - Zero-config connection strings —
WithReference(messaging)injects the broker address into each service as an Aspire connection string;AddKubeMQClient("messaging")reads it back automatically, so no host or port is hard-coded - Built-in health checks — readiness and liveness checks are registered out of the box with
readyandlivetags, surfacing the SDK's connection state to the Aspire dashboard and Kubernetes probes - OpenTelemetry on by default — the SDK's
KubeMQ.Sdktracing source and meter are registered automatically, so traces and metrics flow into the Aspire telemetry pipeline with no extra code - Keyed DI for multiple brokers —
AddKeyedKubeMQClientregisters a distinctIKubeMQClientper named broker, resolved with[FromKeyedServices(...)]
The two packages
| Package | Project | Responsibility |
|---|---|---|
KubeMQ.Aspire.Hosting | AppHost | Provision KubeMQ containers in the Aspire AppHost |
KubeMQ.Aspire.Client | Service | Configure IKubeMQClient with health checks, OpenTelemetry, and keyed DI |
Install
Add the hosting package to your AppHost project:
dotnet add package KubeMQ.Aspire.HostingAdd the client package to each service project that talks to KubeMQ:
dotnet add package KubeMQ.Aspire.ClientQuick start
Provision the broker in the AppHost and reference it from a service. The connection string flows from the container resource into the service automatically.
var builder = DistributedApplication.CreateBuilder(args);
var kubemqKey = builder.AddParameter("kubemq-key", secret: true);
var messaging = builder.AddKubeMQ("messaging")
.WithLicenseKey(kubemqKey)
.WithDataVolume();
builder.AddProject<Projects.MyWebApi>("webapi")
.WithReference(messaging)
.WaitFor(messaging);
builder.Build().Run();var builder = WebApplication.CreateBuilder(args);
builder.AddKubeMQClient("messaging");
var app = builder.Build();
app.Run();AddKubeMQClient registers IKubeMQClient as a singleton and resolves the broker address from the "messaging" connection string injected by WithReference. For the full walkthrough — parameters, secrets, and verifying the connection — see Getting Started.
Architecture
The AppHost provisions the KubeMQ container and injects its address as a connection string into each referencing service. In the service, AddKubeMQClient reads that connection string, constructs an IKubeMQClient that speaks gRPC to the broker on port 50000, and registers the health checks and OpenTelemetry instrumentation as side outputs into the Aspire pipeline.
The AppHost provisions the broker container and injects its host:port address; the service resolves it by connection name, builds an IKubeMQClient, and gets health checks and telemetry for free.
What the integration provisions
The hosting package provisions a real KubeMQ container; the client package layers Aspire conventions on top of the KubeMQ .NET SDK.
| Feature | Detail |
|---|---|
| Container image | AddKubeMQ runs europe-docker.pkg.dev/kubemq/images/kubemq:2.5.0 |
| gRPC endpoint | Target port 50000 (TCP) — the primary client connection |
| REST endpoint | Target port 9090 (HTTP) |
| Dashboard endpoint | Target port 8080 (HTTP) |
| Persistent lifetime | The container uses ContainerLifetime.Persistent, so it survives AppHost restarts |
| Persistent storage | WithDataVolume() binds a volume to /store for durable messages |
| License key | WithLicenseKey() sets the KUBEMQ_TOKEN environment variable from a secret parameter |
| Image override | WithImageTag() overrides the default image tag |
| Health checks | Readiness (ready) and liveness (live) checks reporting the SDK connection state |
| OpenTelemetry | Tracing source and meter KubeMQ.Sdk registered by default |
| Keyed DI | AddKeyedKubeMQClient for multiple named brokers in one service |
Supported runtime
| Requirement | Version |
|---|---|
| Language | C# (.NET) |
| .NET runtime | .NET 8.0 or .NET 9.0 |
| .NET Aspire | 9.0+ |
KubeMQ.SDK.CSharp | 3.0.1 |
| KubeMQ broker | gRPC on :50000 (always on — no enable flag) |
Messaging patterns
Once IKubeMQClient is injected, it speaks the full KubeMQ messaging surface through the native SDK. The capability pages document the Aspire-specific wiring and link out to the core pattern docs for the send/receive semantics.
Pub/Sub & Events Store
Fire-and-forget Events and persistent Events Store replay through the injected client.
Queues
Durable point-to-point messaging with competing consumers and ack/nack.
Commands & Queries
Synchronous request-response messaging for command and query patterns.
Quick links
Getting Started
Provision a broker, reference it from a service, and send your first message.
Concepts
The two-package model, connection-string injection, keyed DI, and observability.
Client Configuration & TLS
Settings, appsettings.json conventions, health-check tuning, and TLS/mTLS.
Hosting API Reference
Hosting and client extension methods, settings, and configuration keys.
Requirements — .NET 8.0 or .NET 9.0, .NET Aspire 9.0 or later, a KubeMQ license key set via WithLicenseKey(), and Docker for local development with Aspire.
New to KubeMQ? Start with the KubeMQ Getting Started guide for core concepts like Events, Queues, and RPC before wiring up Aspire.
Was this page helpful?