错误:服务器在关闭时返回错误:当前没有应用服务器连接到 Azure 服务“@aspnet/signalr”

西比什维努

我有一个 MXChip 将数据发送到 Azure IoT 中心,从那里我使用带有 Azure SignalR 绑定的 Azure 函数将设备数据发布到 Azure Signal R。我有一个 Angular 客户端,它将通过调用我创建的 Azure 协商函数使用包@aspnet/signalr.

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

下面是我的 Angular 服务代码。

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}`);
            });
        });
    }
}

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

西比什维努

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

serverTimeoutInMilliseconds

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

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

keepAliveIntervalInMilliseconds

ping 服务器的默认时间间隔。

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

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

this.hubConnection.serverTimeoutInMilliseconds = 300000;
this.hubConnection.keepAliveIntervalInMilliseconds = 300000;

我们还可以在onclose事件中再次启动集线器作为临时修复。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

azure + postgresql:如何修复错误:无法连接到服务器:服务器意外关闭了连接

连接到Azure移动服务上托管的Socket.IO服务器返回错误

内部服务器错误-Azure应用服务自定义控制器

Azure Kubernetes - 没有连接到服务器

内部服务器错误500-托管Microsoft Bot Framework的Azure应用服务

在 Azure 中配置主动-被动 Web 应用服务器

从 Azure 函数应用程序连接到 SQL DB 时找不到 SqlException 服务器错误

客户端无法连接到Azure应用服务上托管的Node.js Websocket服务器吗?

是否有可能没有应用服务器的JMS服务器?

服务器连接到Azure Postgres时意外关闭连接

去应用服务器?

从Azure逻辑应用连接到Azure SQL服务器时出错

使用 Connect HTTP 方法请求时如何删除服务器头 Azure 应用服务

即使应用服务器 puma 关闭,rails 服务器如何提供页面?

在应用服务器关闭后是否立即关闭所有的石英作业?

Azure“远程服务器返回错误:(530)未登录。”

在Azure Web应用中发布出现服务器错误

Azure上的Drupal update.php引发错误“无法连接到服务器”

访问 Azure MobileServices TableController 时出现服务器错误

MySQL 查询在 azure 应用服务 + azure 数据库服务器中始终只返回“1”

Azure PostgreSQL服务器服务排序规则创建错误

无法连接到Azure网站ftp服务器

如何在 Linux 的 Azure 应用服务中使用自定义 DNS 服务器?

启动hadoop时没有错误,但无法连接到服务器

Azure通知服务:远程服务器返回错误:(401)未经授权。ExpiredToken:.TrackingId:

Quarkus内部使用哪个应用服务器?

quarkus使用什么应用服务器?

应用服务器中的线程

Delphi SOAP应用服务器中的WebModule