微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用上游和 Azure Function App 诊断 Azure SignalR 404 中的错误?

如何解决如何使用上游和 Azure Function App 诊断 Azure SignalR 404 中的错误?

我在上游设置了 Azure SignalR 服务。协商工作正常,但我在尝试使用 connection.invoke('events',{ ... });

时收到 404 错误

在 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();
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。