Azure 函数应用程序和 Web 套接字

Azure function apps and web sockets

我看到函数应用程序中有多个地方不支持 Web 套接字。我只想创建一个网络套接字几秒钟,然后再次关闭它。所以我不需要复杂的套接字框架。我想知道为什么不支持此设置? Microsoft 是否开始支持此功能?

Azure Functions 通常以两种方式托管:

  1. 消费计划(无服务器)
  2. 应用服务计划(专用)

消费计划(无服务器)

在这个计划中,底层机器在服务器空闲时取消配置。因此,当机器空闲和取消配置时,您可能会丢失活动的 Web-Socket 连接。

此外,以下是 Microsoft Azure Function 团队的声明:

There are some challenges here because WebSocket is really a stateful protocol (you have a long lived connection between a given client and a given server) while Azure Functions is designed to be stateless. For example, we will often deprovision a Function App from one VM and start it on a different VM (perhaps in a different scale unit) based on capacity constraints. This is safe to do for us today because of our stateless design - but if we did it when there were WebSockets connections to that VM, we'd be terminating those connections. Source: GitHub

应用服务计划(专用)

如果您使用的是专用的应用程序服务计划,那么 Web Sockets 肯定会工作,因为后台有一台机器不是无服务器的(始终可用)。

只需确保您已在配置中启用 Web 套接字(正如您已经完成的那样)。

从这里检查应用服务计划的网络套接字连接限制 - App Service limits