A simple Laravel service provider which adds a new queue connector to handle SNS subscription queues.
joblocal/laravel-sqs-sns-subscription-queue is a Laravel package for a simple laravel service provider which adds a new queue connector to handle sns subscription queues..
It currently has 48 GitHub stars and 452.535 downloads on Packagist (latest version v2.6.5).
Install it with composer require joblocal/laravel-sqs-sns-subscription-queue.
Discover more Laravel packages by joblocal
or browse all Laravel packages to compare alternatives.
Last updated
A simple extension to the Illuminate/Queue queue system used in Laravel and Lumen.
Using this connector allows SQS messages originating from a SNS subscription to be worked on with Illuminate\Queue\Jobs\SqsJob.
This is especially useful in a miroservice architecture where multiple services subscribe to a common topic with their queues.
Understand that this package will not handle publishing to SNS, please use the AWS SDK to publish an event to SNS.
Add the LaravelSqsSnsSubscriptionQueue ServiceProvider to your application.
Registering Service Providers in Laravel
'providers' => [
// ...
Joblocal\LaravelSqsSnsSubscriptionQueue\SqsSnsServiceProvider::class,
],
Registering Service Providers in Lumen
$app->register(Joblocal\LaravelSqsSnsSubscriptionQueue\SqsSnsServiceProvider::class);
You'll need to configure the queue connection in your config/queue.php
'connections' => [
'sqs-sns' => [
'driver' => 'sqs-sns',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'queue' => env('SQS_QUEUE', 'your-queue-url'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'routes' => [
// you can use the "Subject" field
'Subject' => 'App\\Jobs\\YourJob',
// or the "TopicArn" of your SQS message
'TopicArn:123' => 'App\\Jobs\\YourJob',
// to specify which job class should handle the job
],
],
],
Once the sqs-sns queue connector is configured you can start using it by setting queue driver to 'sqs-sns' in your .env file.
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
/**
* Example Job class
*/
class Job implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @param string $subject SNS Subject
* @param array $payload JSON decoded 'Message'
*/
public function __construct(string $subject, array $payload)
{
}
}
When SNS publishes to SQS queues the received message signature is as follows:
{
"Type" : "Notification",
"MessageId" : "63a3f6b6-d533-4a47-aef9-fcf5cf758c76",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Subject" : "Testing publish to subscribed queues",
"Message" : "Hello world!",
"Timestamp" : "2017-03-29T05:12:16.901Z",
"SignatureVersion" : "1",
"Signature" : "...",
"SigningCertURL" : "...",
"UnsubscribeURL" : "..."
}
Illuminate\Queue\Jobs\SqsJob requires the following signature:
{
"job": "Illuminate\\Queue\\CallQueuedHandler@call",
"data": {
"commandName": "App\\Jobs\\YourJob",
"command": "...",
}
}
The best way to install laravel-sqs-sns-subscription is by using Composer.
To install the most recent version:
php composer.phar require joblocal/laravel-sqs-sns-subscription-queue