⚠ Deprecated: Legacy
Suggested alternative: JoeDevSharp.MqttNet.ReactiveBinding
Mqtt.Net.Orm is a lightweight Reactive Object Mapper (ROM) for MQTT-based applications in .NET. It abstracts MQTT topics as strongly typed, observable entities, enabling developers to handle real-time data streams using LINQ-style syntax and reactive programming patterns. Inspired by Entity Framework’s DbContext and DbSet<T> model, Mqtt.Net.Orm brings structure and clarity to messaging-driven systems by treating MQTT topics as first-class, observable data sources. This makes it easier to reason about, subscribe to, filter, and publish MQTT messages without dealing directly with low-level client code.
License
—
Deps
2
Install Size
—
Vulns
✓ 0
Published
May 24, 2025
$ dotnet add package Codevia.MqttReactiveObjectMapperMqtt.Net.Orm is a lightweight Reactive Object Mapper (ROM) for MQTT-based applications in .NET. It abstracts MQTT topics as strongly typed, observable entities, enabling developers to handle real-time data streams using LINQ-style syntax and reactive programming patterns.
Inspired by Entity Framework’s DbContext and DbSet<T> model, Mqtt.Net.Orm brings structure and clarity to messaging-driven systems by treating MQTT topics as first-class, observable data sources. This makes it easier to reason about, subscribe to, filter, and publish MQTT messages without dealing directly with low-level client code.
[Topic] attributes on classes, making the topic-to-entity relationship explicit.IObservable<T> and Where(...).Subscribe(...) for reactive, filtered event handling..Publish(entity) method, hiding low-level MQTT details.MqttContext to manage all MQTT entities just like a database context..Where() and .Select() on your MQTT streams.IMqttBus, it can be adapted to different MQTT libraries and broker implementations.TopicSet<T>: A typed gateway to subscribe, publish, and filter MQTT messages mapped to the topic defined on type T.MqttOrmContext: The central configuration point that registers all MQTT entities and creates topic sets.IMqttBus: The abstraction over the MQTT client, which handles publishing, subscribing, and stream conversion.TopicAttribute: Metadata annotation that binds a C# class to a specific MQTT topic.Mqtt.Net.Orm promotes a clean, reactive, and domain-driven approach to working with MQTT. Instead of treating MQTT as a generic transport layer with string topics and JSON blobs, it treats it as a structured, type-safe message bus that seamlessly integrates with C#'s type system and LINQ capabilities.
The goal is to minimize boilerplate, enforce consistency, and make reactive MQTT applications more expressive and maintainable.
Let me know if you'd like this reformatted as a README.md, or integrated with badges, install instructions, and GitHub action workflows. I can also generate an architectural diagram or visual overview if needed.
Mqtt.Net.Orm is a lightweight framework that simplifies working with MQTT topics as strongly typed reactive entities in .NET applications. Inspired by Entity Framework, it enables a structured, observable, and declarative approach to working with real-time MQTT data.
Install the NuGet package:
dotnet add package Mqtt.Net.OrmOr reference the project directly if you’re working from source.
Each entity class must be annotated with the [Topic] attribute to define the corresponding MQTT topic.
using Mqtt.net.ORM.Attributes;
public class DHT230222_Modules
{
public double Temperature { get; set; }
public double Humidity { get; set; }
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}The context exposes topic sets as typed properties, similar to EF’s DbSet<T>. Each topics must be annotated with the [Topic] attribute to define the corresponding MQTT topic.
public class MqttContext : MqttOrmContext
{
[Topic("iot/devices/dht/module1")]
public TopicSet<DHT230222_Modules> DHT230222_Modules { get; }
public MqttContext()
{
DHT230222_Modules = Set<DHT230222_Modules>();
}
}Subscribe to incoming messages using LINQ-like filters:
_context.DHT230222_Modules
.Where(m => m.Temperature > 20)
.Subscribe(m =>
{
Console.WriteLine($"High temperature: {m.Temperature}");
});Subscriptions are reactive and automatically connected to the MQTT bus.
Send messages to the corresponding topic using the Publish method:
_context.DHT230222_Modules.Publish(new DHT230222_Modules
{
Temperature = 22.5,
Humidity = 50.0
});Publishing is handled asynchronously behind the scenes, but Publish() blocks until the operation is completed.
static void Main(string[] args)
{
var context = new MqttContext();
context.DHT230222_Modules.Subscribe(m =>
{
Console.WriteLine($"Received: Temp = {m.Temperature} °C, Humidity = {m.Humidity} %");
});
context.DHT230222_Modules.Publish(new DHT230222_Modules
{
Temperature = 18.0,
Humidity = 45.0
});
Console.ReadLine(); // Keep the application alivez
}.Where() to filter messages and reduce unnecessary processing..Subscribe(); use async delegates or background workers.Q: Can I use MQTT wildcards (+, #)?
Yes, set AllowWildcards = true in the [Topic] attribute.
Q: What does Set<T>() do in the context?
It returns a TopicSet<T> that manages publishing and subscribing to the associated MQTT topic.
Q: Is this compatible with any MQTT broker? Yes. The library works with any broker that supports standard MQTT 3.1.1/5.0 (e.g., Mosquitto, HiveMQ, EMQX).