SignalR Hubconnection 未收到来自 Azure 函数应用的任何消息

问题描述

首先,我创建了一个 HTTP 触发器函数

public static class Negotiate
{
    [FunctionName("Negotiate")]
    public static SignalRConnectionInfo Run(
        [HttpTrigger(AuthorizationLevel.Anonymous,"post",Route = null)] HttpRequest req,ILogger log,[SignalRConnectionInfo(HubName = "col")] SignalRConnectionInfo connectionInfo)
    {
        return connectionInfo;
    }
}

接下来,我已将 SignalR 绑定添加到 Azure 函数(服务总线触发器)

[SignalR(HubName = "col")] IAsyncCollector<SignalRMessage> signalRMessage

然后,当我尝试使用此 SignalR 绑定推送消息时

var list = GetPatientAR();
await signalRMsg.AddAsync(new SignalRMessage
{
 Target = "patientarlist",Arguments = new[] { list }
});

使用 HubConnectionBuilder 构建的连接根本没有收到来自此 Azure 函数的任何消息。

HubConnectionBuilder 的代码是:

private collectionHubConnection: signalR.HubConnection;

public startConnection() {
   this.collectionHubConnection = new signalR.HubConnectionBuilder()
  .withUrl("http://localhost:7071/api",{
    skipNegotiation: false,transport: signalR.HttpTransportType.WebSockets
  }).build();
this.collectionHubConnection.start()
  .then(() => console.log("collection SIGNALR CONN DONE"))
  .catch(err => console.log("collection SIGNALR ERROR:" + err));
}

ngOnInit() {
  this.startConnection();
}


loadPatientAR() {
this.collectionservice.getPatientARData().subscribe((data) => {
  this.patientarary = data;
  console.log("Patient AR DATA FROM API",this.patientarary);
});
this.collectionHubConnection.on("patientarlist",(data) => {
  this.patientarary = data
  console.log("par data",data);
})
}

signalr 的服务模式是 Serverless。 我也没有收到任何错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)