-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take a first crack at creating an SQS class
Toward openva/rs-video-processor#57.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* Interact with AWS’ Simple Queuing Service. | ||
*/ | ||
class SQS | ||
{ | ||
|
||
use Aws\Sqs\SqsClient; | ||
|
||
public function __construct() | ||
{ | ||
|
||
$this->sqs_client = new SqsClient([ | ||
'profile' => 'default', | ||
'region' => 'us-east-1', | ||
'version' => '2012-11-05', | ||
'key' => AWS_ACCESS_KEY, | ||
'secret' => AWS_SECRET_KEY | ||
]); | ||
|
||
} | ||
|
||
/** | ||
* Send a message via SQS. | ||
*/ | ||
function send() | ||
{ | ||
|
||
if (!isset($this->message)) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
$this->sqs_client->sendMessage([ | ||
'MessageGroupId' => '1', | ||
'MessageDeduplicationId' => mt_rand(), | ||
'QueueUrl' => SQS_VIDEO_URL, | ||
'MessageBody' => json_encode($this->message) | ||
]); | ||
|
||
return TRUE; | ||
|
||
} | ||
|
||
/** | ||
* Get a message via SQS. | ||
*/ | ||
function get() | ||
{ | ||
|
||
$result = $this->sqs_client->ReceiveMessage([ | ||
'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/947603853016/rs-video-harvester.fifo' | ||
]); | ||
|
||
return TRUE; | ||
|
||
} | ||
|
||
/** | ||
* Delete a message from SQS. | ||
*/ | ||
function delete() | ||
{ | ||
|
||
$this->sqs_client->DeleteMessage([ | ||
'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/947603853016/rs-video-harvester.fifo', | ||
'ReceiptHandle' => $message['ReceiptHandle'] | ||
]); | ||
|
||
return TRUE; | ||
|
||
} | ||
|
||
} |