0

I am new to firebase cloud messaging and i search the best way to send notifications to clients.

I want people to be able to subscribe to new entry in subcollection like this :

books/{bookID}/comments/{commentId}/reply/{replyId}}

Is that bad if i use that kind of syntax? so i can push notification on that topic when new reply are created

void fcmSubscribe(String bookId,String commentId) {
    firebaseMessaging.subscribeToTopic('book-${bookiD}_comment-${commentId}');
  }

or i need to use Individual Device Notifications and create entries like this

books/{bookID}/comments/{commentId}/notifications/{tokenId}}

i want to avoid firestore Read and Write.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Jason Simard
  • 103
  • 5
  • 18

1 Answers1

1

You can use whatever valid topic names that you want. Use whatever you like - it's your choice. There is nothing particularly "bad" about your choice of name, as long as it works for you. Things can only go badly for you if you exceed one of the documented limits for topic messaging:

Topic messaging supports unlimited subscriptions for each topic. However,

FCM enforces limits in these areas:

  • One app instance can be subscribed to no more than 2000 topics.
  • If you are using batch import to subscribe app instances, each request is limited to 1000 app instances.
  • The frequency of new subscriptions is rate-limited per project. If you send too many subscription requests in a short period of time, FCM servers will respond with a 429 RESOURCE_EXHAUSTED ("quota exceeded") response. Retry with exponential backoff.

If you're thinking that FCM is tied in any way to Firestore, that's not the case. You are not obliged to make anything match between your Firesore documents and your FCM topics.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441