I'm very new to MQTT, but have been using .Net for years. I have an existing process that gets data and sends commands to an external device. But I have a new customer that wants that data to be sent to their process using MQTT. I understand the basic MQTT protocol, but I'm trying to implement it in .Net. Here is my setup:
The communication between my Broker and the device is well-established. But I'm trying to understand the implementation of MQTT in the broker so that it can both receive commands from the application, and publish data to the application. There are only a few implementations of MQTT in .net out there, and from what I've found, they use older versions of MQTT, not 5.0 and the samples from MQTTnet on Github are a little confusing.
So my questions are:
- Is it true that I need to create both an mqtt client and an mqtt server in the Broker for this implementation?
- In the Client code, can I create a single client once and keep it as a local variable or do I need to dispose of it?
- What is the correct event to register on the client to get published messages - is it
ApplicationMessageReceivedAsync
?