rafiulgits/mqtt-client-dotnet-core

how to publish a topic and message in controller?

hongshulin126 opened this issue · 1 comments

how to publish a topic and message in controller?

public class MyController : ControllerBase
{
    private readonly IMqttClientService mqttClientService;
    public MyController(MqttClientServiceProvider provider)
    {
        mqttClientService = provider.MqttClientService;
      // invoke mqttClientService methods and attribute
    }
}

Way : 1

make mqttClient attribute public to available for access

image


Way : 2
Add a new method(s) IMqttClientService which will interpret with mqttClient method(s). Just like PublishToMqttAsync to invoke mqttClient.PublishAsync