kirschbaum / laravel-sns-subscription-queues
A Laravel package that allows the queueing system to deal with the non-laravel payload when subscribed to an AWS SNS topic.
Installs: 1 384
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.4.0
- illuminate/config: ~5.1
- illuminate/queue: >=5.1.20 <5.2
- illuminate/support: ~5.1
Requires (Dev)
- aws/aws-sdk-php: ~3.0
- mockery/mockery: ~0.9.4
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-11-29 05:32:25 UTC
README
Laravel SNS Subscription Queues
Under Active Development
This package is actively being developed and should be considered experimental for the time being.
Laravel Version Support
Due to some changes that were made in Laravel version 5.1.20 this package currently only supports version 5.1.20 and higher. It does not support v5.2.0 or higher at this time.
Usage
This package extends the default Illuminate\Queue\QueueServiceProvider
to handle queue payloads from SNS Topic subscriptions. It works by checking for a custom handler configuration in the event the Job doesn't meet the expected Laravel payload structure. If a custom queue handler has been configured this package then adds the necessary structure so that the queue system can process the Job.
Installation
Add the package to your project:
For now update your composer.json
"config": { "preferred-install": "dist" }, "minimum-stability": "dev"
then
composer require kirschbaum/laravel-sns-subscription-queues
Add the following service provider:
// config/app.php
'providers' => [
...
Kirschbaum\LaravelSnsSubscriptionQueues\ServiceProvider::class,
...
];
Publish the config file using the Artisan command:
php artisan vendor:publish --provider="Kirschbaum\LaravelSnsSubscriptionQueues\ServiceProvider"
The configuration looks like this:
<?php
return [
/*
|--------------------------------------------------------------------------
| Custom Handlers for SNS Subscription Queues
|--------------------------------------------------------------------------
|
| Here is where we map an ARN Topic to the Laravel Job handler that should
| process the queue payload.
|
*/
// Examples
'arn:aws:sns:us-east-1:012345667910:my-sns-topic-name' => 'App\\Jobs\\MyCustomHandler@handle',
'arn:aws:sns:us-east-1:012345667910:my-other-sns-topic-name' => 'App\\Jobs\\AnotherCustomHandler@handle',
];
Create a corresponding Laravel Job class to handle the payload:
<?php namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyCustomHandler extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public function handle($sqs_job, $payload)
{
$this->setJob($sqs_job);
// Process the job here.
$this->delete();
}
}