Giter Site home page Giter Site logo

How to route Messages about mqttnet HOT 10 CLOSED

dotnet avatar dotnet commented on May 13, 2024
How to route Messages

from mqttnet.

Comments (10)

chkr1011 avatar chkr1011 commented on May 13, 2024 1

Hi,
your code likes fine so far. For your case you need one server and several clients. So you need a parameter to distinguish the clients in your client code (i.e. parameter).

It is not possible to send a message directly to a special client. You can only publish a message to the server. Depending on the topic several clients can subscribe to that topic. You can build your own patterns based on it. So if you need to send a message to client1 you can send them to something like client/1/messages and client1 is the only one who has subscribed that topic. For example with client/1/+.

Please find more information here: http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices

If you have more questions please let me know.

Best regards
Christian

from mqttnet.

Zuendelmeister avatar Zuendelmeister commented on May 13, 2024

Hi @chkr1011,
thanks for your fast response and the link.
I tried out the following:
Client_2:

var applicationMessage = new MqttApplicationMessage(
"client/1/messages",
Encoding.UTF8.GetBytes("Hello World"),
MqttQualityOfServiceLevel.ExactlyOnce,
false
);
Console.WriteLine("Sending");
client.PublishAsync(applicationMessage);

And Client_1:

client.Connected += async (s,e) =>
{
Console.WriteLine("### CONNECTED WITH SERVER ###");
await client.SubscribeAsync(new List
{
new TopicFilter("client/1/+", MqttQualityOfServiceLevel.AtLeastOnce)
});

And it worked like a charm. Thank you so much!
But to my second question: Can the server log somehow the incomming messages?

Best regards,
Zuendelmeister

from mqttnet.

chkr1011 avatar chkr1011 commented on May 13, 2024

You can use the MqttTrace class to attach a handler for general trace and debug messages. But there you will not see the content of the messages etc.
Or do you need something different?

from mqttnet.

Zuendelmeister avatar Zuendelmeister commented on May 13, 2024

I was hoping to log all incomming and outgoing messages in the broker program. But if thats not possible I have to live without it. Thanks.

from mqttnet.

chkr1011 avatar chkr1011 commented on May 13, 2024

I can add it if you like. It should be not a huge change. You need the ApplicationMessages and the sending ClientId only? I assume you don't need the low level packages or?

from mqttnet.

Zuendelmeister avatar Zuendelmeister commented on May 13, 2024

Gread that would be awsome.
What I need is the ApplicationMessage, the ClientId, the MqttQualityOfServiceLevel and the topic. The retain information could come in handy too but this is not important.
Thank you =)

from mqttnet.

chkr1011 avatar chkr1011 commented on May 13, 2024

OK this what you need is all part of the ApplicationMessage excluding the ClientId. I will add a event which gives you both. Give me a few days to implement it.

from mqttnet.

Zuendelmeister avatar Zuendelmeister commented on May 13, 2024

Perfect =)

from mqttnet.

chkr1011 avatar chkr1011 commented on May 13, 2024

Hi, I added this feature to master. Please test it and tell me if it fits your needs. It is a new event at the MqttServer available.

from mqttnet.

chkr1011 avatar chkr1011 commented on May 13, 2024

I released a new version. If you need something please let me know (open the ticket).

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.