简体   繁体   English

谷歌云运行无法连接MQTT

[英]Google cloud run unable to connect MQTT

Currently I am developing a.Net6 application with a some controllers and a minimal MQTT Server.目前我正在开发带有一些控制器和最小 MQTT 服务器的 .Net6 应用程序。 So far I have everything working correctly on my local machine, however, when deploying to Google Cloud Run (GCR) I am unable to connect to the MQTT Server.到目前为止,我的本地机器上一切正常,但是,当部署到 Google Cloud Run (GCR) 时,我无法连接到 MQTT 服务器。

I noticed that the GCR container wants you to map incoming traffic to a single port (8080 in my case), however I am running MQTT on port 1883 (default) and unable to connect to it.我注意到 GCR 容器希望您将 map 传入流量发送到单个端口(在我的例子中是 8080),但是我在端口 1883(默认)上运行 MQTT 并且无法连接到它。 The controllers running on port 8080 are accessible and work fine.在端口 8080 上运行的控制器可以访问并且工作正常。

I need some direction toward a solution, preferably in a single container.我需要一些解决方案的方向,最好是在一个容器中。

Program.cs程序.cs

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseKestrel(o =>
{
    o.ListenAnyIP(1883, l => l.UseMqtt()); 
    o.ListenAnyIP(8080);
});

...

var app = builder.Build();

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
    endpoints
        .MapConnectionHandler<MqttConnectionHandler>("/mqtt",
            httpConnectionDispatcherOptions =>
                httpConnectionDispatcherOptions.WebSockets.SubProtocolSelector = protocolList => protocolList.FirstOrDefault() ?? string.Empty);
});

app.UseMqttServer(server => server.StartAsync());
app.MapControllers();
app.Run();

A possible option is to not use 2 ports.一个可能的选择是不使用 2 个端口。

If you use MQTT over WebSockets then your broker can share a port with the HTTP server.如果您在 WebSockets 上使用 MQTT,那么您的代理可以与 HTTP 服务器共享一个端口。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 mqtt.js 连接到运行在谷歌云虚拟机实例上的 Mosquitto MQTT Broker - How to connect to Mosquitto MQTT Broker, that is running on a Google Cloud Virtual Machine Instance, using mqtt.js 无法连接到基本的 Google Cloud Run 服务:上游连接错误或在标头之前断开连接/重置。 复位原因:远程复位错误 - Unable to connect to basic Google Cloud Run service: upstream connect error or disconnect/reset before headers. reset reason: remote reset error 为什么我无法通过 MQTT 连接到 Google Cloud IOT Core 中的设备? - Why can't I connect to device in Google Cloud IOT Core through MQTT? 无法将 datalust/seq 部署到 Google Cloud Run - Unable to deploy datalust/seq to Google Cloud Run 无法通过 SSH 连接到 Google Cloud VM 错误代码 4010 - Unable to connect to Google Cloud VM via SSH Error code 4010 托管在 Google Cloud Run 的 Ghost 尝试连接到 Cloud SQL MySQL 并超时读取通信数据包 - Ghost hosted at Google Cloud Run tries to connect to Cloud SQL MySQL and gots timeout reading communication packets 谷歌云运行端口 - Google Cloud Run Port 如何使 ssh 从谷歌计算引擎隧道连接到数据库服务器,并尝试从谷歌云运行连接 - How to make ssh tunneling from google compute engine to database server, and try to connect from google cloud run 无法从 filezilla 客户端连接到 Cloud Run 中部署的 SFTP 服务器映像 - Unable to connect to SFTP-server image deployed in Cloud Run from filezilla client 同一注册表中 2 台设备之间的 Google Cloud MQTT 消息交换 - Google Cloud MQTT message exchange between 2 devices in the same registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM