jeudi 15 octobre 2015

How to subscribe multiple device token at one time in AWS SNS

I am Using AWS SNS for sending push notification in Android and iOS devices. Can anyone tell me how to subscribe multiple device tokens at the same time (not one by one).

I have already code for one by one subscription of a device token.

CreateTopicRequest createTopicRequest = new CreateTopicRequest("MyNewTopic");
    CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest);

    //print TopicArn
    System.out.println(createTopicResult);
    //get request id for CreateTopicRequest from SNS metadata
    System.out.println("CreateTopicRequest - " +  snsClient.getCachedResponseMetadata(createTopicRequest));

    String topicArn = createTopicResult.getTopicArn()

    CreatePlatformApplicationResult platformApplicationResult
    String platformApplicationArn = ''

    long now = System.currentTimeMillis()
    println("----before-subscription-------" + now)

    platformTokens.each { String platformToken ->

        try {
            platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential);
        } catch (Exception e) {
            System.out.println("----------------" + e)
        }

        platformApplicationArn = platformApplicationResult.getPlatformApplicationArn();
        CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn);

        String endpointArn = platformEndpointResult.getEndpointArn()
    // System.out.println("------------endpointArn--------------" + endpointArn);

      //subscribe to an SNS topic
        SubscribeRequest subRequest = new SubscribeRequest(topicArn, "application", endpointArn);
        snsClient.subscribe(subRequest);

With one by one subscription is taking lot of time for more than 100 device tokens. SO please help me to solve my problem.

Thanks




Aucun commentaire:

Enregistrer un commentaire