https://github.com/mmuecke/rxmqttnet
A extension to the MQTTnet project, to transform the subscriptions into observables and to publish form a observalbe stream.
https://github.com/mmuecke/rxmqttnet
comunication csharp iot mqtt-client mqtt-protocol net netcore nuget rx
Last synced: about 17 hours ago
JSON representation
A extension to the MQTTnet project, to transform the subscriptions into observables and to publish form a observalbe stream.
- Host: GitHub
- URL: https://github.com/mmuecke/rxmqttnet
- Owner: mmuecke
- License: mit
- Created: 2020-10-19T16:21:35.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-09-20T16:10:37.000Z (almost 2 years ago)
- Last Synced: 2026-06-05T02:05:49.691Z (about 2 months ago)
- Topics: comunication, csharp, iot, mqtt-client, mqtt-protocol, net, netcore, nuget, rx
- Language: C#
- Homepage:
- Size: 295 KB
- Stars: 30
- Watchers: 2
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
 [](https://codecov.io/gh/mmuecke/RxMQTTnet)
[](https://www.nuget.org/packages/MQTTnet.Extensions.External.RxMQTT.Client)
[](https://www.nuget.org/packages/MQTTnet.Extensions.External.RxMQTT.Client)
# RxMQTTnet
An extension to the [MQTTnet](https://github.com/chkr1011/MQTTnet) project, to transform the subscriptions into observables and to publish from an observable stream.
# Create a client
## Use the factory
Use the `MQTTnet.MqttFactory` with the `MQTTnet.Extensions.External.RxMQTT.Client.MqttFactoryExtensions`.
```csharp
var client = new MqttFactory().CreateRxMqttClient();
```
## Create the options
Use the [managed client options](https://github.com/chkr1011/MQTTnet/wiki/ManagedClient#preparation)
## Start the client
```csharp
await client.StartAsync(options).ConfigureAwait(false);
```
# Subscribe
Get an `IObservable` by connecting to the rx client and use extensions to process the message:
```csharp
var subscription = rxMqttClinet
.Connect("RxClientTest/#")
.SelectPayload()
.Subscribe(Console.WriteLine);
```
End the subscription by disposing the subscription.
```csharp
subscription.Dispose();
```
# Publish
## From observable
Create an observable sequence of `MqttApplicationMessage`s and publish these via the rx client.
```csharp
Observable.Interval(TimeSpan.FromMilliseconds(1000))
.Select(i => new MqttApplicationMessageBuilder()
.WithTopic("RxClientTest")
.WithPayload("Time: " + DateTime.Now.ToLongTimeString())
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce)
.WithRetainFlag()
.Build())
.PublishOn(mqttClient)
.Subscribe();
```
## Single message
Use the [mqtt client publish method](https://github.com/chkr1011/MQTTnet/wiki/Client#publishing-messages).