Comments (4)
// See https://aka.ms/new-console-template for more information
using MQTTnet;
using MQTTnet.Client;
Console.WriteLine("Hello, World!");
var mqttFactory = new MqttFactory();
var mqttClient = mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("10.132.105.8")
.WithClientId("ebb46a457522466882bdb6d316fa29f3")
.Build();
// Setup message handling before connecting so that queued messages
// are also handled properly. When there is no event handler attached all
// received messages get lost.
mqttClient.ApplicationMessageReceivedAsync += e =>
{
Console.WriteLine("Received application message.");
Thread.Sleep(500);
return Task.CompletedTask;
};
await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
f =>
{
f.WithTopic("/iothub/#");
})
.Build();
await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);
Console.ReadLine();
topic: /iothub/a
这个主题一秒钟有100条数据包
from mqttnet.
Google Translate: 'Das Abonnieren von Themenszenarien mit hoher Parallelität kann zu Speicherverlusten führen'
from mqttnet.
@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500));
Does this change anything?
from mqttnet.
@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500)); Does this change anything?
I agree, the rest of the code looks good for me.
from mqttnet.
Related Issues (20)
- No valid replacement for the obsolete MqttClientOptionsBuilder.WithConnectionUri HOT 1
- MQTTnet.AspTestApp Fails to start HOT 1
- MQTTnet.Extensions.WebSocket4Net uses several outdated and possibly vulnerable dependencies HOT 4
- MQTT-over-Websocket connection reconnects every 30 seconds (MAUI regression) HOT 1
- Can't connect to broker using CA Cert ClientCert and Key HOT 2
- Unable to connect with Unix Socket HOT 4
- Last Will not working? HOT 2
- [FR] Protobuf HOT 4
- PublishAsync doesn't return a result nor exception HOT 4
- Linux - when Upgrading from version 4.3.3.952 to 4.3.4.1084 the client always raises the exception «None of the discovered or specified addresses match the socket address family» HOT 7
- Restore messages per client/subscription HOT 2
- No connection could be made because the target machine actively refused it. HOT 1
- Breaking Change in MqttClientTcpOptions with 4.3.5.1141 HOT 5
- Managed MQTT client hangs when trying to disconnect using `StopAsync()` in Unity Engine HOT 4
- UWP PublishAsync forever hangs
- Event when pending ApplicationMessage was published HOT 1
- MqttClientOptionsBuilder.WithTcpServer:The “_remoteEndPoint” is missing instantiation
- Json serialized messages wont get published to the broker. HOT 2
- Connecting To localhost...Could not open connection to the host, on port 1883: Connect failed HOT 2
- The type or namespace name 'Options' does not exist in the namespace 'MQTTnet.Client' (are you missing an assembly reference?) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttnet.