Angular 错误:服务器在关闭时返回错误:当前没有应用服务器连接到Azure服务'@aspnet/信号机

Angular 错误:服务器在关闭时返回错误:当前没有应用服务器连接到Azure服务'@aspnet/信号机,angular,azure,azure-functions,mxchip,azure-signalr,Angular,Azure,Azure Functions,Mxchip,Azure Signalr,我有一个MXChip,它将数据发送到Azure IoT集线器,从那里我使用Azure Signal R绑定的Azure函数将设备数据发布到Azure Signal R。我有一个Angular客户端,它将通过调用我创建的Azure协商函数来获取连接信息,使用包@aspnet/Signal R 但问题是我的Angular客户端每隔几秒钟就会抛出一个错误,当我检查时,我可以理解hubConnection.onclose事件每隔几秒钟就会触发一次 下面是我的角度服务代码 export class Sig

我有一个MXChip,它将数据发送到Azure IoT集线器,从那里我使用Azure Signal R绑定的Azure函数将设备数据发布到Azure Signal R。我有一个Angular客户端,它将通过调用我创建的Azure协商函数来获取连接信息,使用包
@aspnet/Signal R

但问题是我的Angular客户端每隔几秒钟就会抛出一个错误,当我检查时,我可以理解
hubConnection.onclose
事件每隔几秒钟就会触发一次

下面是我的角度服务代码

export class SignalRService {
    mxChipData: Subject < string > = new Subject();
    private hubConnection: SignalR.HubConnection;

    constructor(private http: HttpClient) {}

    private getSignalRConnection(): Observable < SignalRConnection > {
        return this.http.get < SignalRConnection > (`${environment.baseUrl}negotiate`);
    }

    init() {
        this.getSignalRConnection().subscribe(con => {
            const options = {
                accessTokenFactory: () => con.accessToken
            };

            this.hubConnection = new SignalR.HubConnectionBuilder()
                .withUrl(con.url, options)
                .configureLogging(SignalR.LogLevel.Information)
                .build();

            this.hubConnection.on('notify', data => {
                this.mxChipData.next(data);
            });

            this.hubConnection.start()
                .catch(error => console.error(error));

            this.hubConnection.onclose((error) => {
                console.error(`Something went wrong: ${error}`);
            });
        });
    }
}
导出类信号服务{
mxChipData:Subject=新主题();
专用hubConnection:signal.hubConnection;
构造函数(私有http:HttpClient){}
私有getSignalConnection():可观察{
返回this.http.get(`${environment.baseUrl}协商`);
}
init(){
this.getSignalConnection().subscribe(con=>{
常量选项={
accessTokenFactory:()=>con.accessToken
};
this.hubConnection=new signal.HubConnectionBuilder()
.withUrl(con.url,选项)
.configureLogging(信号器.LogLevel.Information)
.build();
this.hubConnection.on('notify',data=>{
this.mxChipData.next(数据);
});
this.hubConnection.start()
.catch(error=>console.error(error));
this.hubConnection.onclose((错误)=>{
error(`Something出错:${error}`);
});
});
}
}

有什么办法可以摆脱这种行为吗?

我想出了一个简单的解决办法。
signal.HubConnection
具有属性
servertimeoutinmillimess
keepaliveintervalinmillimess

servertimeoutinems

服务器超时(以毫秒为单位)

如果此超时时间过去而未从服务器接收任何消息,则连接将因错误而终止。默认超时值为30000毫秒(30秒)

保持间隔百万秒

ping服务器的默认间隔

默认值为15000毫秒(15秒)。允许服务器检测硬断开连接(如客户端拔下计算机时)

我只是将这些值设置为更大的数字

this.hubConnection.serverTimeoutInMilliseconds = 300000;
this.hubConnection.keepAliveIntervalInMilliseconds = 300000;
我们还可以在
onclose
事件中作为临时修复程序再次启动集线器

this.hubConnection.onclose((error) => {
    this.hubConnection.start();
    console.error(`Something went wrong: ${error}`);
});

我想出了一个简单的解决办法。
signal.HubConnection
具有属性
servertimeoutinmillimess
keepaliveintervalinmillimess

servertimeoutinems

服务器超时(以毫秒为单位)

如果此超时时间过去而未从服务器接收任何消息,则连接将因错误而终止。默认超时值为30000毫秒(30秒)

保持间隔百万秒

ping服务器的默认间隔

默认值为15000毫秒(15秒)。允许服务器检测硬断开连接(如客户端拔下计算机时)

我只是将这些值设置为更大的数字

this.hubConnection.serverTimeoutInMilliseconds = 300000;
this.hubConnection.keepAliveIntervalInMilliseconds = 300000;
我们还可以在
onclose
事件中作为临时修复程序再次启动集线器

this.hubConnection.onclose((error) => {
    this.hubConnection.start();
    console.error(`Something went wrong: ${error}`);
});

尝试将信号器服务模式切换到无服务器(或经典)


尝试将信号机服务模式切换到无服务器(或经典)


请不要回答其他答案中提出的问题。请不要回答其他答案中提出的问题。