我开始修补 Azure SignalR,但遇到了 negiotate 触发器的问题。我遵循了这个官方的微软指南:
这是我的代码:
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-trigger 的 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
. 其他人说要编辑local.settings.json。这些都对我没有任何影响,我找不到关于这个问题的任何有用信息。
编辑 1:我设置"hubName":"jitsi"
. 作为jitsi
我的 SignalR 服务的名称。如'jitsi.service.signalr.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.