简体   繁体   中英

How to use Laravel 5 to receive Amazon SNS message from SQS?

I am trying to get the email response (bounce, complaint and delivery) from Amazon SES through SNS. On Amazon SQS console, I see that the message is already in the queue, so I am sure the setting for structures on Amazon is correct.

Then, using Laravel 5.5, following the official guide , I set up a queue listening to SQS. I skip the part of dispatching jobs to the queue as this will be done by SNS. In the job handler, for simplicity, I just var_dump what I receive. The job looks like this:

public function handle($testing_message)
{
    var_dump($testing_message);
    echo "testing handle!\n";
}

The config for that looks something like this:

'sqs' => [
    'driver' => 'sqs', //mainly to show that I am using the correct driver
    'key' => env('SQS_KEY', 'your-public-key'),
    'secret' => env('SQS_SECRET', 'your-secret-key'),
    'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
    'queue' => env('SQS_QUEUE', 'your-queue-name'),
    'region' => env('SQS_REGION', 'us-east-1'),
],

For security, The actual value is hidden in .env . I then run:

composer require aws/aws-sdk-php ~3.0
php artisan config:cache
php artisan queue:listen

However, the process just sit there running, no response and no error message.

I want to ask:

  1. How do I know if the connection to the queue is correct?
  2. If the connection is correct, why there is no return from SQS? (I am sure there are already message inside SQS queue from the Amazon console)

I'm not sure why you are using a queue rather than a simple https endpoint. That removes a lot of complexity and doesn't require polling.

There is a simple php example that shows what is needed.

The biggest gotcha is that you need to be able to confirm the SNS subscription before SNS will start sending POST requests to your endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM