[英]How to run multiple asp.net core MQTT broker on one windows server?
I implemented a MQTT broker by asp.net core 2.2 and want to run it on a Windows server 2016. I am using MQTTnet version 2.8.5 for implementing this broker.我通过 asp.net core 2.2 实现了一个 MQTT 代理,并希望在 Windows Server 2016 上运行它。我正在使用 MQTTnet 2.8.5 版来实现这个代理。 This is my startup code:
这是我的启动代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<MyMqttServer>();
services.AddMvc();
var mqttServerOptions = new MqttServerOptionsBuilder()
.WithDefaultEndpointPort(1886)
.Build();
services
.AddHostedMqttServer(mqttServerOptions)
.AddMqttConnectionHandler()
.AddConnections()
.AddMqttTcpServerAdapter();
}
public void Configure(IApplicationBuilder app, MyMqttServer myMqttServer)
{
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMqttServer(server =>
{
server.Started += async (sender, args) => await myMqttServer.RunAsync();
});
}
and this is my code in Program.cs这是我在 Program.cs 中的代码
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(o =>
{
o.ListenAnyIP(1885, l => l.UseMqtt()); // mqtt pipeline
o.ListenAnyIP(5000); // default http pipeline
})
.UseStartup<Startup>()
.Build();
I have two different MQTT broker applications with these settings for MQTT (the other one is set on port 1883 and 1884 in startup) but with different ports.我有两个不同的 MQTT 代理应用程序,这些应用程序具有 MQTT 的这些设置(另一个在启动时设置在端口 1883 和 1884 上)但具有不同的端口。 The problem is only one of these MQTT brokers (the broker that works on 1883,1884) works at the same time and the other one does not work.
问题是这些 MQTT 代理中只有一个(在 1883,1884 上工作的代理)同时工作,而另一个不工作。 How can I solve that?
我该如何解决?
Thanks to JanEggers in MQTTNET team he helped me to solve the issue.感谢 MQTTNET 团队的 JanEggers,他帮助我解决了这个问题。 The problem was I have a class myMqttServer that overrides the settings in startup and main class.
问题是我有一个类 myMqttServer 覆盖启动和主类中的设置。 So I needed to remove those settings and do it in myMqttServer class.
所以我需要删除这些设置并在 myMqttServer 类中进行。 You can see the details in this github link.
您可以在此 github 链接中查看详细信息。
https://github.com/chkr1011/MQTTnet/issues/566 https://github.com/chkr1011/MQTTnet/issues/566
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.