1

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

Community
  • 1
  • 1
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166

1 Answers1

5

Pass 1,000 IDs at a time. A single message cannot have more than 1,000 recipients.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Added a sample as per your suggestion, is it ok? – Gaurav Agarwal Jan 12 '13 at 23:00
  • @codingcrow: Does it compile? When you run it, do the messages get delivered, or do you get an error back from GCM about having too many recipients (or anything else)? If it compiles and it runs, it presumably is OK. – CommonsWare Jan 12 '13 at 23:37
  • I did not try it yet. Does sending so many messages is a problem? – Gaurav Agarwal Jan 12 '13 at 23:45
  • @codingcrow: Since the documentation cites an example of sending to one million recipients (1,000 at a time), it stands to reason that sending to 50,000 recipients (1,000 at a time) should be OK. – CommonsWare Jan 12 '13 at 23:51