3

我目前正在评估 AWS AppSync 作为消息传递应用程序的后端解决方案。

用户将有一个视图来探索新的聊天组和一个不同的视图,他们可以在其中看到他们加入的和私人聊天的列表(在列表中应该显示聊天的名称和最后一条消息)。每个聊天当然都会有一个详细视图,其中显示所有消息。

问题是如何设计订阅部分。我发送消息的突变将如下所示:

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

根据订阅文档,我只有两种设计订阅的可能性。通过使用对话 ID 作为参数,我订阅所有新消息或来自特定对话的所有新消息。因此,在我的情况下,我需要获取所有用户对话,然后为每个对话进行订阅调用。不知何故,这感觉像是一个问题,但我没有看到不同的方式(例如,目前无法进行自定义过滤(根据此链接)

是否有更好的方法来订阅特定消息子集的新消息(仅在我订阅的对话中)?客户端上可能有 100 多个活动订阅是一个问题吗?

提前感谢卢卡

4

1 回答 1

3

You are correct. The only two ways to do this out of the box is to:

  1. Subscribe to each conversation using an argument.
  2. Subscribe to all conversations and filter messages on the client.

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. Create an index where you can find clients given a conversation. The client will make one subscription with one argument (probably a client id). When you publish messages, you have an intermediate step (probably a backend job which is subscribed to all messages) where you look in the index to determine which clients are interested in the conversation you are publishing a message for. Then publish for each client.
于 2018-09-10T17:46:56.200 回答