Subscribe to a List of Group / Private Chats in AW

2019-05-18 09:04发布

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条回答
▲ chillily
2楼-- · 2019-05-18 09:29

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.
查看更多
登录 后发表回答