【问题标题】:Check in Azure Functions if client is still connected to SignalR Service如果客户端仍连接到 SignalR 服务,请签入 Azure Functions
【发布时间】:2020-01-31 17:49:14
【问题描述】:

我在 Azure Functions 中创建了协商和发送消息函数(类似于下面的示例)以合并 SignalR 服务。我正在使用自定义身份验证机制在SignalRMessage 上设置UserId

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service?tabs=csharp

[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
    [HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req, 
    [SignalRConnectionInfo
        (HubName = "chat", UserId = "{headers.x-ms-client-principal-id}")]
        SignalRConnectionInfo connectionInfo)
{
    // connectionInfo contains an access key token with a name identifier claim set to the authenticated user
    return connectionInfo;
}

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            // the message will only be sent to this user ID
            UserId = "userId1",
            Target = "newMessage",
            Arguments = new [] { message }
        });
}

如果客户端不再连接,我想发送推送通知,而不是向IAsyncCollector 添加新对象。我还正确设置了AppCenter 推送框架,但我遇到了一个问题。有没有一种简单的方法可以找出哪个UserId 仍然连接到集线器?这样,我可以决定发送推送。在此问题上推荐的 Microsoft 指南是什么?

【问题讨论】:

    标签: c# push-notification signalr azure-functions visual-studio-app-center


    【解决方案1】:

    看看这个功能:Azure SignalR Service introduces Event Grid integration feature,其中 SignalR 服务 发出以下两种事件类型:

    Microsoft.SignalRService.ClientConnectionConnected
    
    Microsoft.SignalRService.ClientConnectionDisconnected
    

    更多详情here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 2018-08-24
      • 1970-01-01
      相关资源
      最近更新 更多