PHP code example of ndthuan / aws-sqs-wrapper

1. Go to this page and download the library: Download ndthuan/aws-sqs-wrapper 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/ */

    

ndthuan / aws-sqs-wrapper example snippets


use Aws\Sqs\SqsClient;
use Ndthuan\AwsSqsWrapper\Publishing\Publisher;
use Ndthuan\AwsSqsWrapper\Queue\Connector;

$queueUrl = ''; // get this from your own AWS SQS setup

// creating a publisher
$sqsClient = new SqsClient(...);
$queueConnector = new Connector($sqsClient, $queueUrl);
$publisher = new Publisher($queueConnector);

// send a string message
$publisher->publishString('My message body');
// or send a json serializable object/array
$myMessage = [
    'my' => 'data',
];
$publisher->publishJsonSerializable($myMessage);

use Aws\Sqs\SqsClient;
use Ndthuan\AwsSqsWrapper\Queue\Connector;
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage;
use Ndthuan\AwsSqsWrapper\Queue\ResultMetadata;
use Ndthuan\AwsSqsWrapper\Subscribing\DelegatorSubscriber;

// defining a message processor
class MyMessageProcessor implements MessageProcessorInterface
{
    /**
     * @inheritdoc
     */
    public function processMessage(ReceivedMessage $message, ResultMetadata $resultMetadata)
    {
        // your processing logic
    }
}

$queueUrl = ''; // get this from your own AWS SQS setup

// creating a subscriber
$sqsClient = new SqsClient(...);
$queueConnector = new Connector($sqsClient, $queueUrl);
$subscriber = new DelegatorSubscriber(new MyMessageProcessor(), $queueConnector);

// run the subscriber
$subscriber->pullAndProcessMessages();