amazon web services - AWS SQS practical code PHP -


i had question here
i'm still missing point understanding how use sqs, out code please.

question: 1 place inside sqs?
i've read through amazons tutorial , concept seems lovely im missing practical side of things.
instance, diagram great: http://awsmedia.s3.amazonaws.com/catalog/images/159-for-madhu.png
go inside sqs? understand how upload s3, still grey sqs part

require_once('sdk-1.5.6.2/sdk.class.php'); //random strings $aws_key = "my_access_key"; $aws_secret_key = "my_secret_key";   //create new sqs queue , grab queue url $sqs = new amazonsqs(array( "key" => $aws_key, "secret" => $aws_secret_key )); $response = $sqs->create_queue('test-topic-queue'); $queue_url = (string) $response->body->createqueueresult->queueurl; $queue_arn = 'arn:aws:sqs:us-east-1:encq8gqracxv:test-topic-queue';    $queue_arn = 'arn:aws:sqs:us-east-1:encq8gqracxv:test-topic-queue'; $topic_arn = 'arn:aws:sns:us-east-1:encq8gqracxv:test-topic'; $response = $sns->subscribe($topic_arn, 'sqs', $queue_arn); $subscription_arn = (string) $response->body->subscriberesult->subscriptionarn;     /*  *   * * * * * * * * * * * * * * * *       big grey area, happens here ???   *   * * * * * * * * * * * * * * * * */    // delete sqs queue $queue_url = 'https://sqs.us-east-1.amazonaws.com/encq8gqracxv/test-topic-queue';  $response = $sqs->delete_queue($queue_url); 

you should have 2 processes, 1 inserts messages queue , worker threads. typical worker thread this:

while(true) {     $res = $client->receivemessage(array(         'queueurl'          => $url,         'waittimeseconds'   => 1     ));     if ($res->getpath('messages')) {          foreach ($res->getpath('messages') $msg) {             echo "received msg: ".$msg['body'];              // useful $msg['body'] here              $res = $client->deletemessage(array(                 'queueurl'      => $url,                 'receipthandle' => $msg['receipthandle']             ));         }     } } 

the waittimeseconds parameters means "long polling" , has various benefits (see http://docs.aws.amazon.com/awssimplequeueservice/latest/sqsdeveloperguide/sqs-long-polling.html).

you should use supervise or monit make sure worker threads stay running.

update: api v3 use get() instead of getpath() - getpath deprecated


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -