-
Notifications
You must be signed in to change notification settings - Fork 144
feat(fcm): Add SendEachAsync and SendEachForMulticastAsync for FCM batch send
#348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…343) * Implement `SendEachAsync` and `SendEachForMulticastAsync` `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 `SendResponse`s. 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. * Add integration tests for the batch-send reimplementation: SendEach() and SendEachForMulticast()
| /// </summary> | ||
| /// <exception cref="FirebaseMessagingException">If an error occurs while sending the | ||
| /// messages.</exception> | ||
| /// <param name="messages">Up to 500 messages to send in the batch. Cannot be null.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean. Could you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-null and non-empty? or just non null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think empty is also not ok. It's the same for SendAllAsync, but we didn't explicitly mention this for SendAllAsync in the past. Should I change it to "Cannot be null or empty." for both all SendAll APIs and all SendEach APIs? Or should I keep SendAll API as they are now and only update the comment for SendEach APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept SendAll API unchanged and updated to "Cannot be null or empty." for all SendEach APIs.
SendEachAsync and SendEachForMulticastAsync for FCM batch sendSendEachAsync and SendEachForMulticastAsync for FCM batch send
lahirumaramba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
|
@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 |
|
@hankovich |
|
Do we have similar option available in .net sdk? firebase/firebase-admin-node#2488 (comment) |
SendAllAsync() andSendMulticastAsyncAPIs.SendEachAsyncandSendEachForMulticastAsyncAPIsSendEachAsyncvsSendAllAsyncSendEachAsyncsends one HTTP request to V1 Send endpoint for each message in the list.SendAllAsyncsends only one HTTP request to V1 Batch Send endpoint to send all messages in the list.SendEachAsynccallsTask.WhenAllto wait for allhttpClient.SendAndDeserializeAsynccalls to complete and construct aBatchResponsewith allSendResponses. AnhttpClient.SendAndDeserializeAsynccall 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 inSendEachAsyncand turned into aSendResponsewith an exception. Therefore, unlikeSendAllAsync,SendEachAsyncdoes not always throw an exception for a total failure. It can also return aBatchResponsewith only exceptions in it.SendEachForMulticastAsynccallsSendEachAsyncunder the hood.RELEASE NOTE:
SendAllAsync()andSendMulticastAsync()APIs are now deprecated. UseSendEachAsync()andSendEachForMulticastAsync()APIs instead.