PHP code example of bariseser / sqs
1. Go to this page and download the library: Download bariseser/sqs library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bariseser / sqs example snippets
$consumer = (new SqsConsumer())
->setQueueUrl("http://localhost:4566/000000000000/client_api.fifo");
while (true) {
$messages = $consumer->messages();
if (!empty($messages->get('Messages'))) {
foreach ($messages->get('Messages') as $message) {
echo $message['Body'].PHP_EOL;
}
} else {
echo "No messages in queue". PHP_EOL;
}
}
$producer = (new SqsConsumer())
->setQueueUrl("http://localhost:4566/000000000000/client_api.fifo");
$producer->setMessageBody(json_encode(['title' => "baris eser", 'id' => 12345]))->publish();