Subscribe to a List of Group / Private Chats in AWS AppSync

人盡茶涼 提交于 2020-01-01 07:09:10

问题


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

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?

Thanks in advance Luca


回答1:


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.


来源:https://stackoverflow.com/questions/52257282/subscribe-to-a-list-of-group-private-chats-in-aws-appsync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!