acdphp / laravel-sns-sqs-queue
Fanout Laravel queue jobs with AWS SNS and SQS for microservices communication.
v1.0.0
2023-12-26 19:33 UTC
Requires
- php: ^8.0
- aws/aws-sdk-php: ^3.295
Requires (Dev)
- ekino/phpstan-banned-code: ^1.0
- larastan/larastan: ^2.7
- laravel/pint: ^1.5
- mockery/mockery: ^1.6
- orchestra/testbench: ^7.37
- pestphp/pest: ^1.23
- pestphp/pest-plugin-laravel: ^1.4
- phpstan/phpstan: ^1.10
README
Fanout Laravel queue jobs with AWS SNS and SQS for microservices communication.
Installation
-
Install the package
composer require acdphp/laravel-sns-sqs-queue
-
Add new queue connection in your
config/queue.php
. (Similar to default sqs connection but with addedendpoint
andsns_topic_arn
)'connections' => [ ... 'sns-sqs' => [ 'driver' => 'sns-sqs', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 'queue' => env('SQS_QUEUE', 'default'), 'suffix' => env('SQS_SUFFIX'), 'after_commit' => false, 'endpoint' => env('AWS_ENDPOINT'), 'sns_topic_arn' => env('SNS_TOPIC_ARN', 'arn:aws:sns:us-east-1:your-account-id:topic'), ], ]
-
Usage
- Globally set your
QUEUE_CONNECTION
tosns-sqs
- OR Job specific (recommended to only use this for microservice message jobs):
class MicroserviceMessageJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public function __construct($yourData, $anotherData) { $this->onConnection('sns-sqs'); }
- Globally set your
Notes
- Fanout Jobs must exist in all applications that should handle the message with the same namespace and constructor arguments for it work properly.
- Publishing to SNS uses HTTP/S protocol which is synchronous. This means that your job dispatch will hold off the process until the SNS responds back. Consider using a better technology, for instance, using AMQP (like this library) for better performance.
License
The MIT License (MIT). Please see License File for more information.