Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linfx/mqttfx
MqttFx is a mqtt v3.1.1 client using DotNetty
https://github.com/linfx/mqttfx
dotnetty mqtt
Last synced: about 2 months ago
JSON representation
MqttFx is a mqtt v3.1.1 client using DotNetty
- Host: GitHub
- URL: https://github.com/linfx/mqttfx
- Owner: linfx
- License: mit
- Created: 2015-09-06T06:31:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-25T00:58:16.000Z (over 2 years ago)
- Last Synced: 2024-08-31T15:57:26.381Z (4 months ago)
- Topics: dotnetty, mqtt
- Language: C#
- Homepage:
- Size: 486 KB
- Stars: 94
- Watchers: 16
- Forks: 43
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MqttFx
c# mqtt 3.1.1 client
***
## Install
`PM> Install-Package MqttFx`
## Samples
```c#class Program
{
static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddMqttFxClient(options =>
{
options.Host = "broker.emqx.io";
options.Port = 1883;
});
var container = services.BuildServiceProvider();var client = container.GetService();
client.ConnectedAsync += async e =>
{
Console.WriteLine("### CONNECTED WITH SERVER ###");Console.WriteLine("### SUBSCRIBED ###");
var subscriptionRequests = new SubscriptionRequestsBuilder()
.WithTopicFilter(f => f.WithTopic("testtopic/a"))
.WithTopicFilter(f => f.WithTopic("testtopic/b").WithAtLeastOnceQoS())
.Build();var subscribeResult = await client.SubscribeAsync(subscriptionRequests);
foreach (var item in subscribeResult.Items)
{
Console.WriteLine($"+ ResultCode = {item.ResultCode}");
}
};client.ApplicationMessageReceivedAsync += async message =>
{
Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
Console.WriteLine($"+ Topic = {message.Topic}");
Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(message.Payload)}");
Console.WriteLine($"+ QoS = {message.Qos}");
Console.WriteLine($"+ Retain = {message.Retain}");
Console.WriteLine();await Task.CompletedTask;
};var connectResult = await client.ConnectAsync();
if (connectResult.Succeeded)
{
for (int i = 1; i <= 3; i++)
{
await Task.Delay(500);
Console.WriteLine("### Publish Message ###");var mesage = new ApplicationMessageBuilder()
.WithTopic("testtopic/ab")
.WithPayload($"HelloWorld: {i}")
.WithQos(MqttQos.AtLeastOnce)
.Build();await client.PublishAsync(mesage);
}
}
else
Console.WriteLine("Connect Fail!");Console.ReadKey();
}
}```
## MQTT 规范
你可以通过以下链接了解与查阅 MQTT 协议:
[MQTT 协议中文版](https://mcxiaoke.gitbooks.io/mqtt-cn/content/)
[MQTT Version 3.1.1](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html)
[MQTT Version 5.0](https://docs.oasis-open.org/mqtt/mqtt/v5.0/cs02/mqtt-v5.0-cs02.html)
[MQTT SN](https://www.oasis-open.org/committees/download.php/66091/MQTT-SN_spec_v1.2.pdf)