Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No service for type 'MQTTnet.Server.MqttServer' has been registered. #1889

Closed
296370493 opened this issue Dec 5, 2023 · 0 comments · Fixed by #1892
Closed

No service for type 'MQTTnet.Server.MqttServer' has been registered. #1889

296370493 opened this issue Dec 5, 2023 · 0 comments · Fixed by #1892
Labels
bug Something isn't working

Comments

@296370493
Copy link

My project uses MQTTnet AspNetCore encountered an exception after upgrading to version 4.3.2.930, but there is no problem using version 4.3.1.873 for the same code.

`using MQTTnet.Server;
using MQTTnet.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddConnections();
builder.Services.AddMqttServer(configure =>
{
configure.WithKeepAlive();
configure.WithDefaultEndpoint();
});
builder.Services.AddMqttTcpServerAdapter();
builder.Services.AddMqttWebSocketServerAdapter();
var app = builder.Build();

app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapMqtt("/mqtt"));
app.UseMqttServer(configure =>
{
configure.ValidatingConnectionAsync += Configure_ValidatingConnectionAsync;
});
app.Run();

Task Configure_ValidatingConnectionAsync(ValidatingConnectionEventArgs arg)
{
if (string.IsNullOrWhiteSpace(arg.ClientId))
{
arg.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.ClientIdentifierNotValid;
return Task.CompletedTask;
}
if (string.IsNullOrWhiteSpace(arg.UserName) || arg.Password != "testPassword")
{
arg.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.BadUserNameOrPassword;
}
return Task.CompletedTask;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant