问题
I need to send more than one message to a single topic in just one second.
I have three Android devices and I'm trying to send multiple downstream messages to a topic (the three devices are subscribed to) in a short period of time (one second). Our server does ACK for the three of them.
In that moment, we send two messages to the topic, but one of them returns NACK with an error message of TOPICS_MESSAGE_RATE_EXCEEDED
.
And now, we retry to resend the message again, if time_to_live
doesn't expire first. In our case, that message tried re-sending again when the user clicks on it again. Is this the correct behavior?
Did anyone have this problem before? How is it solved?
回答1:
This is the expected behavior for GCM/FCM. Sending multiple messages to a topic in a short amount of time will cause this error.
I think this serves as a safety net for GCM/FCM against flooding and is also about handling the traffic. Just imagine if you have a 1000 subscribers then you send multiple multiple messages in less than a second to that topic.
You should implement a delay (about 5-10 seconds) for each message you send to the topic.
Also mentioned by @Eran's answer here (which is based from the docs):
Topics Message Rate Exceeded The rate of messages to subscribers to a particular topic is too high. Reduce the number of messages sent for this topic, and do not immediately retry sending.
来源:https://stackoverflow.com/questions/40240832/topics-message-rate-exceeded-when-sending-more-than-one-message-in-a-short-perio