azure - 在 Azure Functions 的 SignalR 服务中向一组用户发送消息
问题描述
查看 SignalR 绑定的文档以向指定用户发送消息,您UserId
在消息中包含该属性 -
[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 these user IDs
UserId = "userId1",
Target = "newMessage",
Arguments = new [] { message }
});
}
此示例直接取自文档,但注释暗示您向多个用户 ID 发送消息,即使该属性是字符串而不是数组。
您将如何指定多个用户?(例如,如果他们一起在私人聊天频道中)或者是评论措辞中的错误,您需要为每个用户发送消息?
对于其他版本的 SignalR,我会将它们放在一个组中,但是函数不存在对此的绑定。
解决方案
最新版本中引入了组操作。
现在你可以:
GroupName
使用in向群组发送消息SignalRMessage
IAsyncCollector<SignalRGroupAction>
使用输出在组中添加/删除用户
推荐阅读
- html - 当包含文本输入字段时,如何防止 flexbox 变宽?
- ios - 如何安排 iOS 用户之间发送的推送通知
- r - 如何在 R 中循环一周中的几天
- ios - Expo ios Build error: You are not allowed to perform this Operation
- flutter - Flutter - seo优化
- tensorflow - 如何通过 GridsearchCV 对 Keras 中的 MLP 模型进行超参数调优?
- docker - Ansible:如何复制 env 文件?
- python - 使用 Anaconda 的问题
- emeditor - Emeditor pro 在文件中查找以查找多个文件
- javascript - react native 变量范围的问题