how to publish a topic and message in controller?
hongshulin126 opened this issue · 1 comments
hongshulin126 commented
how to publish a topic and message in controller?
rafiulgits commented
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
Way : 2
Add a new method(s) IMqttClientService
which will interpret with mqttClient
method(s). Just like PublishToMqttAsync
to invoke mqttClient.PublishAsync