在 AWS AppSync 中订阅群组/私人聊天列表 [英] Subscribe to a List of Group / Private Chats in AWS AppSync
问题描述
我目前正在评估 AWS AppSync 作为消息应用的后端解决方案.
Im currently evaluating AWS AppSync as a backend solution for a messaging app.
用户将有一个浏览新聊天组的视图和一个不同的视图,他们可以在其中看到他们加入的和私人聊天的列表(在列表中应该显示聊天的名称和最后一条消息).当然,每个聊天都会有一个详细视图,其中显示了所有消息.
The users will have a view to explore new Chat Groups and a different view where they see a list of their joined and private Chats (In the list the name and the last message of the chats should be displayed). Each Chat will of course have a detail view where all the messages are displayed.
问题是如何设计订阅部分.我发送消息的 Mutation 将如下所示:
The question is how to design the subscription part. My Mutation to send a message will look something like this:
createMessage(内容:字符串,对话ID:ID!,createdAt: 字符串!,身份证:身份证!): 信息
根据订阅文档,我只有两种可能来设计我的订阅.我使用对话 ID 作为参数订阅所有新消息或来自特定对话的所有新消息.因此,在我的情况下,我需要获取所有用户对话,然后为每个对话进行订阅调用.不知何故,这感觉像是一个问题,但我没有看到不同的方式(例如,目前无法进行自定义过滤(根据此链接))
According to the subscription docs i only have two possibilities to design my subscription. Either i subscribe to all new messages or to all new messages from a specific conversation by using the conversation id as an argument. So in my case i would need to fetch all the user conversations and then make a subscription call for every single conversation. Somehow this feels like a problem, but I don't see a different way (e.g. Custom filtering is not possible currently (according to this link))
是否有更好的方法来订阅特定消息子集的新消息(仅在我订阅的对话中)?客户端上潜在的 100 个活跃订阅是否有问题?
Is there a better way to subscribe to new messages for a specific subset of messages (only in conversations im subscribed to)? Is having potentially 100s of active subscriptions on the client a problem?
提前致谢卢卡
推荐答案
你说得对.开箱即用的唯一两种方法是:
You are correct. The only two ways to do this out of the box is to:
- 使用参数订阅每个对话.
- 订阅客户端上的所有对话并过滤消息.
如果您使用参数(选项 #1)订阅每个会话,您可以在一个 HTTP 请求中批量发送订阅请求.例如.在一个请求中发送最多 50 个具有不同对话参数的订阅.
If you subscribe to each conversation using an argument (option #1), you can batch send the subscribe requests in one HTTP request. E.g. Send up to 50 subscriptions with different conversation arguments in one request.
还有第三种选择,您可以在其中做更多工作以确保客户效率.此选项涉及设置与客户对话的反向索引.
There is a third option, where you can do more work to ensure client efficiency. This option involves setting up a reverse index of conversations to client.
- 创建一个索引,您可以在其中找到给定对话的客户.客户端将使用一个参数(可能是客户端 ID)进行一次订阅.当您发布消息时,您有一个中间步骤(可能是订阅所有消息的后端作业),您可以在其中查看索引以确定哪些客户端对您为其发布消息的对话感兴趣.然后为每个客户发布.
这篇关于在 AWS AppSync 中订阅群组/私人聊天列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!