I am trying to use Google GCM Multicast Messaging as described here. I need to send 50,000 messages simultaneously.
The documentation says I should pass a list of registration id to the Sender.send()
.
My Question I am confused, Should I pass the list with all 50,000 ids or 1000 ids at a time because documentation says "One of the most useful features in GCM is support for up to 1,000 recipients for a single message."
[Edit1] Is this ok?
Sender sender = new Sender(API_KEY);
List<List<String>> regIdsParts = regIdInThousands(getRegistrationIds(), 1000);
for (int i = 0; i < regIdsParts.size(); i++) {
Message message = new Message.Builder()
.addData(MsgKey, message).build();
MulticastResult result = sender.send(message, regIdsParts.get(i), 5);
}
public List<List<String>> regIdInThousands(List<String> list, final int L) {
List<List<String>> parts = new ArrayList<List<String>>();
final int N = list.size();
for (int i = 0; i < N; i += L) {
parts.add(new ArrayList<String>(
list.subList(i, Math.min(N, i + L))));
}
return parts;
}
Method regIdsThousands from this question thanks polygenelubricants