/mqtt-client-dotnet-core

MQTTNet client implementation on ASP.NET Core. Library https://github.com/dotnet/MQTTnet

Primary LanguageC#

MQTT Client ASP.NET Core

This repository is an example of how to use MQTTnet client in ASP.NET core web application with services.

MQTT Client is running in MqttClientService byIHostedService, and it is a singleton service.

To access MqttClientService from other external services inject MQTTClientServiceProvider in service constructor.

Here is an example

public class ExtarnalService
{
    private readonly IMqttClientService mqttClientService;
    public ExtarnalService(MqttClientServiceProvider provider)
    {
        mqttClientService = provider.MqttClientService;
    }
}

Configuration

Configure your MQTT settings in appSettings.json

"BrokerHostSettings": {
    "Host": "localhost",
    "Port": 1883
  },

  "ClientSettings": {
    "Id": "5eb020f043ba8930506acbdd",
    "UserName": "rafiul",
    "Password": "12345678"
  },

Now do whatever you want to do with MQTTClientService!