简体   繁体   English

如何在一台 Windows 服务器上运行多个 ASP.NET 核心 MQTT 代理?

[英]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.

相关问题 在C#asp.net核心2.1中通过用户名和密码在MQTT服务器上验证MQTT客户端 - Authenticating MQTT client on the MQTT server by username and password in C# asp.net core 2.1 将 asp.net 核心运行操作系统从 windows 切换到 linux - switch asp.net core run os from windows to linux 如何从在容器中运行的 ASP.NET 核心应用程序连接到具有集成安全性的 Windows 服务器上的 SQL 服务器 - How to connect from ASP.NET Core application running in a container to SQL Server on Windows Server with Integrated Security 如何使用 Asp.net Core EF Core 在 Web 托管服务器上创建多个数据库 - How To Create multiple database on web hosting server using Asp.net core EF Core ASP.NET Core未连接到Windows Server 2012上的数据库 - ASP.NET Core not connecting to database on Windows Server 2012 如何将 ASP.NET 核心 web 应用程序部署到 ZAEA23489CE3AA9B6406EBB28E0CDA4016 上的 IIS 应用程序 - How to deploy ASP.NET core web application to IIS on Windows Server 2016 如何在没有日志记录和配置文件的情况下运行 ASP.NET Core Kestrel 服务器? - How to run ASP.NET Core Kestrel server without logging and config files? 在一个 razor 视图中创建多个模型(ASP.NET Core) - Multiple create models in one razor view (ASP.NET Core) 从一个位置调用多个 ASP.Net Core 微服务 - Call Multiple ASP.Net Core MicroService from One location 在Windows Azure和本地服务器上运行ASP.NET应用程序 - Run ASP.NET application in Windows Azure AND on a local server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM