Mqtt.Client
1.0.2
dotnet add package Mqtt.Client --version 1.0.2
NuGet\Install-Package Mqtt.Client -Version 1.0.2
<PackageReference Include="Mqtt.Client" Version="1.0.2" />
<PackageVersion Include="Mqtt.Client" Version="1.0.2" />
<PackageReference Include="Mqtt.Client" />
paket add Mqtt.Client --version 1.0.2
#r "nuget: Mqtt.Client, 1.0.2"
#:package Mqtt.Client@1.0.2
#addin nuget:?package=Mqtt.Client&version=1.0.2
#tool nuget:?package=Mqtt.Client&version=1.0.2
Mqtt.Client
A high-performance, low-allocation MQTT 3.1.1 + 5.0 client for .NET — designed to feel like System.Threading.Channels.
🚀 Highlights
- Multi-TFM:
netstandard2.0,netstandard2.1,net8.0,net9.0,net10.0(NativeAOT-clean on net10.0; WebSocket transport requires netstandard2.1+). - Channels-style API —
ChannelReader<MqttMessage>for subscriptions,TryPublish/PublishAsyncfor sending. - Built-in DI extensions, source-generated logging,
System.Diagnostics.Metrics,ActivitySource. - Transports: TCP, TLS, WebSocket, Secure WebSocket.
- SOCKS5 proxy (RFC 1928, with optional RFC 1929 username/password auth) for TCP/TLS.
- Auto-reconnect with exponential backoff + jitter; queued publishes survive reconnect.
- Pluggable session persistence for QoS 1/2 in-flight state.
- Secure defaults — TLS 1.2/1.3, CRL checking, capped incoming packet size.
📦 Install
dotnet add package Mqtt.Client
⚡ Quickstart
using Mqtt.Client;
await using var client = MqttClient.CreateBuilder()
.ConnectTo("mqtts://broker:8883")
.WithClientId("svc-1")
.WithCredentials("user", "pw")
.Build();
await client.ConnectAsync();
await using var sub = await client.SubscribeAsync("sensors/+/temp");
await foreach (var msg in sub.Reader.ReadAllAsync())
{
using (msg) // payloads are pooled by default — dispose after use, don't retain
{
Console.WriteLine($"{msg.Topic}: {msg.Payload.Length} bytes");
}
}
await client.PublishAsync("commands/svc-1", "ping"u8.ToArray());
Low-allocation extras
// Publish a payload that's already split across buffers — no concatenation needed.
ReadOnlySequence<byte> framed = BuildFramedPayload();
await client.PublishAsync("telemetry", framed, MqttQoS.AtLeastOnce);
// Inline-handler subscription: the payload is a true zero-copy slice of the receive buffer,
// valid only inside the handler (no allocation, nothing to dispose). Back-pressure flows to
// the broker while the handler runs.
await client.SubscribeAsync("telemetry/#", msg =>
{
Process(msg.PayloadMemory.Span); // do not retain msg or its payload
return ValueTask.CompletedTask;
});
// Channel subscriptions pool the payload by default (dispose each message). If you need to
// retain messages freely instead, opt back into garbage-collected payloads:
var retaining = MqttClient.CreateBuilder()
.ConnectTo("mqtt://broker:1883")
.Configure(o => o.RetainableInboundMessages = true)
.Build();
📚 Documentation
- Quickstart
- Core concepts — channels-style, threading, backpressure
- Samples — auth, TLS, DI, last-will, MQTT 5 properties
- Advanced — custom transport, persistence, AOT, metrics
- Troubleshooting
- Spec conformance
- Chaos / soak testing — continuous-recovery, no-leak, no-hang ruggedization gate
- Benchmarks — Mqtt.Client vs MQTTnet (full matrix) plus cross-language throughput vs C (Mosquitto, Paho)
- Mqtt.Client.Testing — companion package: an embeddable, in-process MQTT broker for tests (no install, all TFMs, parallel-isolated)
🔍 When to pick MQTTnet instead
MQTTnet is a mature, battle-tested .NET MQTT library that covers ground this client
intentionally doesn't:
- You need a broker in addition to a client.
- You need ASP.NET Core integration (managed clients, hosted broker, middleware).
- You need the broadest possible protocol option coverage and a long support history.
- You're already on it and it serves you well.
Mqtt.Client is focused on being a small, fast, AOT-friendly, channels-style
client library for .NET services. Pick whichever fits your situation; both projects
are MIT-licensed and the protocol wire formats are identical.
🔐 Security
Found something? Please file privately via GitHub Security Advisories — see SECURITY.md.
| 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 is compatible. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Pipelines.Sockets.Unofficial (>= 2.2.16)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.IO.Pipelines (>= 9.0.0)
- System.Memory (>= 4.6.3)
- System.Threading.Channels (>= 9.0.0)
-
.NETStandard 2.1
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Pipelines.Sockets.Unofficial (>= 2.2.16)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.IO.Pipelines (>= 9.0.0)
- System.Threading.Channels (>= 9.0.0)
- WebSocketPipe (>= 0.9.0)
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Pipelines.Sockets.Unofficial (>= 2.2.16)
- WebSocketPipe (>= 0.9.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Pipelines.Sockets.Unofficial (>= 2.2.16)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.IO.Pipelines (>= 9.0.0)
- System.Threading.Channels (>= 9.0.0)
- WebSocketPipe (>= 0.9.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Pipelines.Sockets.Unofficial (>= 2.2.16)
- WebSocketPipe (>= 0.9.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Mqtt.Client:
| Package | Downloads |
|---|---|
|
Crdt.Transport.Mqtt
MQTT pub/sub gossip transport for Crdt.Transport, built on the Mqtt.Client package (MQTT 3.1.1/5.0, TCP/TLS/WebSocket). |
GitHub repositories
This package is not used by any popular GitHub repositories.