Skip to content

Latest commit

 

History

History
47 lines (29 loc) · 993 Bytes

README.md

File metadata and controls

47 lines (29 loc) · 993 Bytes

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!