Azure SignalR Javascript Negotiate "Unable to resolve ...ConnectionStringSetting"



我开始修补Azure SignalR,但遇到了negiate触发器的问题。我遵循了微软的官方指南:

这是我的代码:

local.settings.json

{
"IsEncrypted": false,
"Values": {
"AzureSignalRConnectionString": "Endpoint=https://my.service.signalr.net;AccessKey=myKey=;Version=1.0;",
"FUNCTIONS_WORKER_RUNTIME": "node"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*",
"CORSCredentials": true
}
}

函数.json

{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"name": "req",
"route": "negotiate"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "SignalRConnectionInfo",
"name": "connectionInfo",
"hubName": "jitsi",
"ConnectionStringSetting": "Endpoint=https://my.service.signalr.net;AccessKey=myKey;Version=1.0;",
"direction": "in"
}
]
}

index.js

module.exports = async function (context, req, connectionInfo) {
context.res.body = connectionInfo;
};

它在本地运行良好(不幸的是,这就是指南的结尾(。但如果我访问协商http触发器的URL,我会得到"内部服务器错误500"。日志包含以下输出。

2020-04-23T08:47:32  Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds). 
2020-04-23T08:47:52.070 [Information] Executing 'Functions.jitsiNegotiate' (Reason='This function was programmatically called via the host APIs.', Id=2b791d95-3775-47bb-ade1-ac9005929f61)
2020-04-23T08:47:52.238 [Error] Executed 'Functions.jitsiNegotiate' (Failed, Id=2b791d95-3775-47bb-ade1-ac9005929f61)
Unable to resolve the value for property 'SignalRConnectionInfoAttribute.ConnectionStringSetting'. Make sure the setting exists and has a valid value.

正如您在我的代码中看到的,我确实提供了ConnectionStringSetting

一些人认为这是由于ConnectionStringSetting中的小写/大写"C"引起的。其他人说要编辑local.settings.json。这些都没有对我产生任何影响,我也找不到任何关于这个问题的有用信息。

编辑1:我设置了"hubName":"jitsi"jitsi是我的SignalR服务的名称。就像在"jitsi.service.signar.net"中一样。我不确定这是否正确。也许这就是问题的一部分?

编辑2:我尝试过不为ConnectionStringSetting设置值(这样它就变成了默认值(。给了我同样的错误。我还完全删除了local.settings.json的任何内容,然后重新部署以查看会发生什么。行为和以前一样。我的猜测是,该服务只将该文件用于本地用途(因此得名(。因此,在local.settings.json为空的情况下,没有其他地方可以定义AzureSignalRConnectionString的值。我做了一些挖掘,显然(根据这个帖子(你应该在下定义它

"配置"->"应用程序设置">

所以我用创建了一个新的设置

名称:Azure__SignalR__ConnectionString

值:myMaskedConnectionString

这导致了以下错误:

The SignalR Service connection string must be set either via an 'AzureSignalRConnectionString' app setting, via an 'AzureSignalRConnectionString' environment variable, or directly in code via SignalROptions.ConnectionString or SignalRConnectionInfoAttribute.ConnectionStringSetting.

我找到了这个问题的解决方案:

一开始我很困惑,以为local.settings.json会作为该功能的实时/非本地版本的配置。事实并非如此。它只用于本地执行(可以通过文件名猜测(

因此,问题仍然存在:在哪里/如何编辑Azure门户中所需的设置?

答:首页->所有服务->功能应用程序->MyFunctionApp->平台功能->配置->应用程序设置->新建应用程序设置

name:AzureSignalRConnectionStringvalue MyMaskedConnectionString

然后在function.json中,如下所示:

{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"name": "req",
"route": "negotiate"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "SignalRConnectionInfo",
"name": "connectionInfo",
"hubName": "jitsi",
"direction": "in",
"connectionStringSetting": "AzureSignalRConnectionString"
}
]
}

有了这些设置,它现在对我有效了。

相关内容

最新更新