访问 Azure 无服务器 SignalR 用户组中已连接用户的数量(dotnet 隔离和 Azure Functions V4)
以下代码将用户添加到 signalR 组:
[Function("AddToGroup")]
public SignalROutputEntity AddUserToGroup(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addtogroup/{groupName}/{myId}")]
HttpRequestData req,
string groupName,
string myId)
{
var output = new SignalROutputEntity();
output.Notifications.Add(new
{
userId = myId,
groupName = groupName,
action = "add"
});
output.Response = req.CreateResponse(HttpStatusCode.OK);
return output;
}
public class SignalROutputEntity
{
[SignalROutput(HubName = "myHub", ConnectionStringSetting = "AzureSignalRConnectionString")]
public List<object> Notifications { get; set; } = new();
public HttpResponseData? Response { get; set; }
}
我知道,当用户连接到 signalR 集线器或从 signalR 集线器断开连接以增加或减少某种计数器时,我们可以利用 signalR 上游来侦听和处理事件。除了此方法之外,是否还有一种方法或技术可以查询 Azure SignalR 服务实例以确定每个组的连接用户数?
The following code adds a user to a signalR group:
[Function("AddToGroup")]
public SignalROutputEntity AddUserToGroup(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addtogroup/{groupName}/{myId}")]
HttpRequestData req,
string groupName,
string myId)
{
var output = new SignalROutputEntity();
output.Notifications.Add(new
{
userId = myId,
groupName = groupName,
action = "add"
});
output.Response = req.CreateResponse(HttpStatusCode.OK);
return output;
}
public class SignalROutputEntity
{
[SignalROutput(HubName = "myHub", ConnectionStringSetting = "AzureSignalRConnectionString")]
public List<object> Notifications { get; set; } = new();
public HttpResponseData? Response { get; set; }
}
I am aware that we can leverage signalR upstream to listen to and handle events when a user connects or disconnects to/from the signalR hub to increment or decrement a kind of counter. Aside from this method, is there a method or technique to query the Azure SignalR Service instance to determine the number of connected users per group?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论