firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
357 stars 129 forks source link

feat(fcm): Add `SendEachAsync` and `SendEachForMulticastAsync` for FCM batch send #348

Closed Doris-Ge closed 1 year ago

Doris-Ge commented 1 year ago

SendEachAsync vs SendAllAsync

  1. SendEachAsync sends one HTTP request to V1 Send endpoint for each message in the list. SendAllAsync sends only one HTTP request to V1 Batch Send endpoint to send all messages in the list.
  2. SendEachAsync calls Task.WhenAll to wait for all httpClient.SendAndDeserializeAsync calls to complete and construct a BatchResponse with all SendResponses. An httpClient.SendAndDeserializeAsync call to V1 Send endpoint either completes with a success or throws an exception. So if an exception is thrown out, the exception will be caught in SendEachAsync and turned into a SendResponse with an exception. Therefore, unlike SendAllAsync, SendEachAsync does not always throw an exception for a total failure. It can also return a BatchResponse with only exceptions in it.

SendEachForMulticastAsync calls SendEachAsync under the hood.

RELEASE NOTE: SendAllAsync() and SendMulticastAsync() APIs are now deprecated. Use SendEachAsync() and SendEachForMulticastAsync() APIs instead.

hankovich commented 1 year ago

@Doris-Ge Could you please clarify why sending N requests with 1 notification in each is better rather then sending 1 request with N notifications? For me that fact that I should use SendEachAsync instead of SendAllAsync sounds counterintuitive

Doris-Ge commented 1 year ago

@hankovich SendAllAsync calls the legacy Batch Send API which will be discontinued starting June 20, 2024. That's the main reason why it is replaced by SendEachAsync. SendEachAsynccalls the HTTP v1 API which does not support sending 1 request with N notifications.