Skip to content

Haitony/mqtt-client-dotnet-core

 
 

Repository files navigation

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!

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%