jeudi 2 juillet 2015

Long-polling amazon sqs with android and ios sdk

How would someone achieve this with not using http requests (rest). Is this possible with the native sdks?

On android I am running a "every-2-second" iteration of a intent service call:

scheduleTaskExecutor= Executors.newScheduledThreadPool(10);
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
        public void run() {
            Intent i = new Intent(MainActivity.this, AzureServiceBusHttpService.class);
            i.setAction(AzureServiceBusHttpService.START_LONG_POOL);
            startService(i);
        }
    }, 0, 2, TimeUnit.SECONDS);

And on the service side (xxx is sensible data):

AWSCredentials credentials = new BasicAWSCredentials("xxx", "xxx");
AmazonSQSClient sqsClient = new AmazonSQSClient(credentials);

ReceiveMessageRequest rmr = new ReceiveMessageRequest("http://ift.tt/1LGIkC1";
rmr.setMaxNumberOfMessages(10);
rmr.setVisibilityTimeout(30);

ReceiveMessageResult result = sqsClient.receiveMessage(rmr);

if (result.getMessages().size() > 0) {
    EventBus.getDefault().post(new MsgEvent(result.getMessages().get(0).getBody()));

    DeleteMessageRequest rreq = new DeleteMessageRequest("http://ift.tt/1LGIkC1", result.getMessages().get(0).getReceiptHandle());
    sqsClient.deleteMessage(rreq);
}

I am wondering if this can be improved (reduced calls with long polling)?




Aucun commentaire:

Enregistrer un commentaire