redb.Route.MqttNet
4.8.0
Prefix Reserved
dotnet add package redb.Route.MqttNet --version 4.8.0
NuGet\Install-Package redb.Route.MqttNet -Version 4.8.0
<PackageReference Include="redb.Route.MqttNet" Version="4.8.0" />
<PackageVersion Include="redb.Route.MqttNet" Version="4.8.0" />
<PackageReference Include="redb.Route.MqttNet" />
paket add redb.Route.MqttNet --version 4.8.0
#r "nuget: redb.Route.MqttNet, 4.8.0"
#:package redb.Route.MqttNet@4.8.0
#addin nuget:?package=redb.Route.MqttNet&version=4.8.0
#tool nuget:?package=redb.Route.MqttNet&version=4.8.0
redb.Route.MqttNet
MQTT 5.0 transport for redb.Route via MQTTnet. Subscribe consumer, publish producer, shared subscriptions, QoS levels, retained messages, and TLS.
Installation
dotnet add package redb.Route.MqttNet
Usage
Fluent DSL
using redb.Route.MqttNet;
// Subscribe to topic
From(Mqtt.Subscribe("sensors/temperature/#")
.Server("mqtt.example.com").Port(1883)
.ClientId("route-consumer")
.Qos(1))
.Log("Temperature: ${body}")
.To("direct://process");
// Publish to topic
From("direct://alerts")
.To(Mqtt.Publish("alerts/critical")
.Server("mqtt.example.com")
.Username("svc").Password("secret")
.Qos(2)
.Retain());
// Shared subscription (load balancing across consumers)
From(Mqtt.Subscribe("orders/new")
.Server("broker.local")
.SharedSubscription("order-processors")
.UseTls())
.To("direct://handle-order");
// Broker configuration (shared across routes)
From(Mqtt.Subscribe("events/#")
.Broker("main")
.Qos(1))
.To("seda://events");
Fluent Builder API
| Category | Methods |
|---|---|
| Connection | .Broker(name), .Server(), .Port(), .Username(), .Password(), .ClientId(), .UseTls(), .KeepAlive(), .CleanSession(), .SessionExpiryInterval(), .MaxReconnectDelay() |
| QoS | .Qos(level) — AtMostOnce, AtLeastOnce, ExactlyOnce |
| Subscribe | Mqtt.Subscribe(topic), .SharedSubscription(group), .ConcurrentConsumers(n) |
| Publish | Mqtt.Publish(topic), .Retain(), .MessageExpiryInterval(), .ContentType(), .ResponseTopic() |
Most builder methods accept both constant values and
IExpressionfor runtime resolution via the expression engine.
Headers
| Header | Written by | Read by the publish |
|---|---|---|
redbMqtt.topic |
the consumer (received topic), the producer (topic it published to) | no |
redbMqtt.overrideTopic |
the route only | yes: the topic instead of the endpoint's |
redbMqtt.qos, redbMqtt.retain |
the consumer (received message), the producer (its publish) | no |
redbMqtt.overrideQos (0, 1 or 2), redbMqtt.overrideRetain (true or false), typed or as text |
the route only | yes: QoS and retain flag instead of the endpoint's |
redbMqtt.contentType, redbMqtt.responseTopic, redbMqtt.correlationData, redbMqtt.messageExpiryInterval |
the consumer | yes, passed through: the MQTT 5 properties of the publish |
redbMqtt.userProperties |
the consumer | yes, passed through: MQTT 5 user properties |
redbMqtt.broker, redbMqtt.clientId |
the consumer, the producer | no |
The topic a publish goes to is the endpoint's (an expression such as sensors/${header.room} included), or
redbMqtt.overrideTopic when the route set it. redbMqtt.topic only tells where the last message came from or went,
so two publishes in one route each reach their own endpoint, and a received message republished to a fixed topic goes
there, not back to the topic it came from.
QoS and the retain flag work the same way: the endpoint's (qos, qosExpression, retain), or
redbMqtt.overrideQos / redbMqtt.overrideRetain when the route set them. A retained message received and
republished is not retained again, and goes out with the endpoint's QoS, not the QoS it arrived with.
The MQTT 5 properties are the exception: a message received and republished keeps its content type, response topic, correlation data, expiry interval and user properties, so request/response and metadata survive a hop. A route that does not want them on the publish removes those headers first.
Concurrent processing
.ConcurrentConsumers(n) (default 1 = serial) processes up to n received messages in parallel on a
worker pool. Each message is settled only after its worker finishes, as in serial mode (see
Acknowledgement and failed messages). Ordering is not
preserved when n > 1.
From(Mqtt.Subscribe("telemetry/#").Broker("main").Qos(1).ConcurrentConsumers(5))
.Process(IngestReading);
See the framework-wide Concurrency & Parallelism guide (CONCURRENCY.md in the
redb.Route repository) for how this compares to the .Threads(N)
processing EIP.
Acknowledgement and failed messages
The client speaks MQTT 5.0 (MQTTnet's default protocol). The consumer acknowledges every QoS 1 and QoS 2 message
itself, after the route, in serial and concurrent mode alike; MQTTnet does not acknowledge on receipt. MQTT has no
negative acknowledgement: the broker sends an unacknowledged message again only when the client connects again to a
session the broker kept, and it sends a client no more unacknowledged messages than its receive window. So a message
the route fails on (an exception it did not handle, or .RollbackAll()) is settled by one rule, the one of Apache
Camel's paho-mqtt5 consumer as corrected by CAMEL-25793:
| The failed message | What the consumer does |
|---|---|
QoS 0, or the session ends with the connection (cleanSession=true, the default, or sessionExpiryInterval=0) |
Acknowledges it and logs an error. |
QoS 1 or QoS 2 on a kept session (cleanSession=false and sessionExpiryInterval above 0) |
Leaves it unacknowledged, disconnects and connects again after a pause, so that the broker sends it again. |
What this means for a route:
- Acknowledged and logged means the broker will not send the message again: it is gone from MQTT. Holding the acknowledgement back would not bring it back either, it would only fill the receive window until the consumer stops getting messages. Where a failed message must be kept, the route keeps it with its own error handling: an error handler with redelivery, and a dead letter channel that stores it.
- On a kept session the message comes again after the reconnect and runs through the route again; so do the other messages that were not acknowledged yet when the consumer disconnected, also ones whose route had already finished. A route on a kept session must therefore tolerate a repeat, for example with an idempotent consumer.
- The pause before the reconnect is 1 second and doubles with each failed message in a row, up to
maxReconnectDelay(default 128000 ms); a message that succeeds resets it. A message that always fails is therefore tried at that pace, not in a tight loop. A failure while the consumer is stopping starts no reconnect and is not acknowledged. - A kept session needs a fixed
clientId: the broker finds the session by it. The consumer does not unsubscribe on stop when the session is kept, so the messages that wait in it reach the next start.
mqtt:orders/#?mode=Subscribe&broker=main&qos=1&clientId=orders-in&cleanSession=false&sessionExpiryInterval=3600
Part of
redb.Route — ESB & EIP Framework for .NET
Named connection factory
Keep credentials out of the route URI: register a factory in the context registry and reference it by name. A set-but-unknown name fails loud at startup — a typo can never silently fall back to inline URI parameters.
context.AddToRegistry("prod", new MqttConnectionFactory
{
Server = "mqtt.internal",
Username = "svc",
Password = secrets.MqttPassword,
});
// mqtt://sensors/+?connectionFactory=prod
Concurrency
The default is 1 concurrent consumer — the industry norm (Camel, Spring, the Azure SDK all ship 1): a single consumer preserves ordering and your handlers need no thread safety. Parallelism is an explicit opt-in:
concurrentConsumers=4 # a fixed worker count
concurrentConsumers=auto # max(CPU count, 2) — the NServiceBus formula
Anything else — 0, a negative, a typo — fails at endpoint creation naming the option (the old
int-typed option silently fell back to 1). Raising the value trades ordering for throughput:
messages from the same queue are processed out of order, and your processors must be safe to
run in parallel.
Tracing
On the redb.Route activity source (AddSource("redb.Route")), with messaging.system = mqtt and
redb.route.endpoint:
- Context. The W3C context (
traceparent,tracestate,baggage) travels in MQTT 5 user properties, and only when the connection speaks v5 (the MQTTnet default). Under 3.1.1 nothing is written — MQTTnet refuses user properties there — and nothing is read. - Producer. One
Producerspan per publish,{topic} publish, whose context is written to the message. The write replaces atraceparentalready inredbMqtt.userProperties(copied from an earlier hop); the exchange's header is left as it was. An error when the publish fails, unless our own token cancelled it. - Consumer. One
Consumerspan per routed message,{topic} receive, a child of the sender's context when the message carries one; otherwise a root, never a child of the activity the client's receive loop holds. Nothing arriving opens none. A failed route marks it an error; our own stop does not. RouteEngineOptions.EnableTelemetry = falseopens neither span; a context the route received is still passed on.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net11.0 is compatible. |
-
net10.0
- JsonPath.Net (>= 2.2.0)
- JsonSchema.Net (>= 7.3.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Options (>= 10.0.15)
- MQTTnet (>= 5.2.0.1603)
- redb.Route (>= 4.8.0)
-
net11.0
- JsonPath.Net (>= 2.2.0)
- JsonSchema.Net (>= 7.3.4)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.15)
- MQTTnet (>= 5.2.0.1603)
- redb.Route (>= 4.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.8.0 | 92 | 12/1/2026 |
| 4.7.8 | 101 | 11/30/2026 |
| 4.7.7 | 94 | 11/28/2026 |
| 4.7.6 | 106 | 11/26/2026 |
| 4.7.5 | 102 | 11/24/2026 |
| 4.7.2 | 137 | 11/13/2026 |
| 4.7.1 | 110 | 11/11/2026 |
| 4.7.0 | 106 | 11/7/2026 |
| 4.6.2 | 111 | 11/5/2026 |
| 4.6.1 | 121 | 11/4/2026 |
| 4.6.0 | 114 | 11/3/2026 |
| 4.5.1 | 123 | 10/30/2026 |
| 4.5.0 | 113 | 10/29/2026 |
| 4.4.2 | 115 | 10/23/2026 |
| 4.4.1 | 117 | 10/21/2026 |
| 4.3.0 | 117 | 10/14/2026 |
| 4.2.3 | 113 | 10/8/2026 |
| 4.2.2 | 114 | 10/5/2026 |
| 4.2.0 | 124 | 9/30/2026 |