Giter VIP home page Giter VIP logo

Comments (4)

colincodefirst avatar colincodefirst commented on June 6, 2024

screenshot-20240311-134723

// 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.

SeppPenner avatar SeppPenner commented on June 6, 2024

Google Translate: 'Das Abonnieren von Themenszenarien mit hoher Parallelität kann zu Speicherverlusten führen'

from mqttnet.

MD-V avatar MD-V commented on June 6, 2024

@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500));
Does this change anything?

from mqttnet.

SeppPenner avatar SeppPenner commented on June 6, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.