问题描述
我在上游设置了 Azure SignalR 服务。协商工作正常,但我在尝试使用 connection.invoke('events',{ ... });
在 SignalR 事件日志中,我得到(省略了无关位):
{
"properties": {
"message": "Sending message during operation {hub}=map,{event}=events,{category}=messages got unexpected response with status code 404. Detail: ","type":"MessagingLogs","collection":"Serverless"
},"operationName": "HttpHandlerUnexpectedResponse","callerIpAddress": "null"
}
什么可能导致 404?
有一个带有 events
函数和以下绑定的 Azure Function 应用程序设置:
{
"disabled": false,"bindings": [
{
"authLevel": "anonymous","type": "httpTrigger","direction": "in","name": "req","methods": [
"post"
]
},{
"type": "http","direction": "out","name": "res"
},{
"type": "signalR","name": "$return","hubName": "map","direction": "out"
}
]
}
我相信函数应用程序设置正确。我有以下设置作为我的上游(在实际调用中替换了信息:
<function_app_server>/runtime/webhooks/signalr?code=<signalr_extension_key>
解决方法
显然,在使用 Upstream 时,Azure 的绑定发生了变化。以下绑定有效:
{
"bindings": [
{
"type": "signalRTrigger","name": "invocation","hubName": "map","category": "messages","event": "events","parameterNames": [
"message"
],"direction": "in",},{
"type": "signalR","name": "signalRMessages","connectionStringSetting": "AzureSignalRConnectionString","direction": "out"
}
]
}
module.exports = function (context,invocation) {
context.bindings.signalRMessages = [{
"target": "newMessage",// name of the client method to invoke
"arguments": [
context.bindingData.message // arguments to pass to client method
]
}];
context.done();
};