Client connected to broker but controller throws InvalidOperationException: The MQTT server is not started
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Program.cs:
```
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseKestrel(o =>
{
o.ListenAnyIP(1883, l => l.UseMqtt());
o.ListenAnyIP(5000);
});
var optionBuilder = new MqttServerOptionsBuilder()
.WithoutDefaultEndpoint()
.Build();
builder.Services.AddControllers();
builder.Services.AddHostedMqttServer(optionBuilder);
builder.Services.AddMqttConnectionHandler();
builder.Services.AddConnections();
var app = builder.Build();
app.UseAuthorization();
app.MapControllers();
app.Run();
```
StatusController.cs:
```
private readonly MqttHostedServer _mqttServer;
public StatusController(MqttHostedServer mqttServer)
{
_mqttServer = mqttServer;
}
[HttpGet]
public async Task GetConnectedClientsAsync()
{
var clients = await _mqttServer.GetClientsAsync();
return Ok(clients);
}
```
Line `var clients = await _mqttServer.GetClientsAsync();` throws InvalidOperationException: The MQTT server is not started, but client can connect successufuly. Do I have two instances of Mqtt server in my app? How to do it in .NET 6? I saw documentation and samples for .NET 5 but I can't make it work.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.