订阅AWS AppSync中的群组/私人聊天列表 [英] Subscribe to a List of Group / Private Chats in AWS AppSync

查看:148
本文介绍了订阅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.

问题是如何设计订阅部分.我的发送消息的变异看起来像这样:

The question is how to design the subscription part. My Mutation to send a message will look something like this:

createMessage( content: String, conversationId: ID!, createdAt: String!, id: ID! ): Message

createMessage( content: String, conversationId: ID!, createdAt: String!, id: ID! ): Message

根据订阅文档,我只有两种可能性来设计我的订阅.通过使用对话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))

是否有更好的方法来订阅特定消息子集的新消息(仅在已订阅的会话中)? 客户端上潜在的数百个活动订阅是否有问题?

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. 使用参数订阅每个对话.
  2. 订阅所有对话并过滤客户端上的消息.

如果使用参数(选项#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.

  1. 创建一个索引,您可以在其中找到进行对话的客户.客户端将使用一个参数(可能是客户端ID)进行一次订阅.发布消息时,您有一个中间步骤(可能是订阅了所有消息的后端作业),在其中查找索引以确定哪些客户端对要为其发布消息的对话感兴趣.然后为每个客户发布.

这篇关于订阅AWS AppSync中的群组/私人聊天列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆