Download the PHP package gabebritto/laravel-simple-sqs without Composer
On this page you can find all versions of the php package gabebritto/laravel-simple-sqs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gabebritto/laravel-simple-sqs
More information about gabebritto/laravel-simple-sqs
Files in gabebritto/laravel-simple-sqs
Package laravel-simple-sqs
Short Description A Laravel package for asynchronous microservice communication via SQS with raw JSON payloads.
License MIT
Informations about the package laravel-simple-sqs
Laravel Simple SQS Messenger
This Laravel package is designed to facilitate asynchronous microservices communication via AWS SQS using pure JSON payloads (without Laravel's native PHP serialization).
With this library, you can integrate and map incoming external JSON messages directly to standard Laravel Jobs, maintaining full compatibility with Laravel's native queue workers (php artisan queue:work).
JSON Payload Structure
All messages sent and received must strictly adhere to this flat format:
Installation & Setup
1. Requirements
Ensure that the sqs queue driver and the AWS SDK are already configured in your host Laravel application (config/queue.php).
2. Registering the Package
In your main Laravel application's composer.json, add the local path repository:
Then, install the package using:
3. Publish Configurations
Publish the package configuration file using the artisan publish command:
This will generate the config/sqs-messenger.php file:
How it Works
The package provides the Gabebritto\LaravelSimpleSqs\Traits\SqsJsonJob trait, which automates serialization (dispatching) and deserialization/hydration (consuming) of the queue messages.
1. Publisher (Dispatching Messages)
You have three clean and robust ways to dispatch raw JSON messages to the queue:
Option A: Static Dispatching via the Job class (Recommended)
The SqsJsonJob trait automatically resolves the mapped alias from the configuration file and sends the payload in pure JSON format:
Option B: Dynamic Instantiation & Publishing
If you prefer to instantiate the Job and define its public properties, the trait extracts the public properties of the class (filtering out Laravel's internal properties) and sends them as the JSON payload. event is just a standard property of the job:
Option C: Directly via the SqsPublisher Facade
You can also dispatch arbitrary payloads without having a local Job class or a configuration mapping defined:
2. Consumer (Receiving Messages / Worker)
Your Consumer Job can be a standard Laravel Job (implementing ShouldQueue and using traits like InteractsWithQueue and Queueable), simply by importing the SqsJsonJob trait.
The trait takes care of the following actions automatically upon receiving the message:
- Intercepts the native Laravel queue worker execution.
- Extracts and populates the
$this->payloadproperty (which is the direct content of"data"). - Auto-hydrates properties: Matches keys in the payload to public properties declared on the class (supports both
camelCaseandsnake_caseproperties, includingeventif present in the payload). - Links the raw SQS job instance to enable standard job manipulation methods (e.g.
$this->release()). - Executes the standard
handle()method, allowing method-level dependency injection. - Automatically deletes the message from SQS on successful execution.
Example (app/Jobs/ConsolidateJob.php):
Why does it work with Laravel's native Worker?
When the native worker runs (php artisan queue:work), it pulls the SQS message, decodes the raw JSON, and attempts to resolve the value inside the "job" key from Laravel's Service Container.
In the register method of the SqsMessengerServiceProvider, we bind each configured alias to its class:
Since the received JSON contains "job": "external-event", the worker resolves and creates an instance of \App\Jobs\ConsolidateJob. By default, when no specific method is defined in the job payload (like Class@method), the queue runner falls back to calling the fire() method.
The SqsJsonJob trait defines the fire($job, array $data) method. This method hydrates the class properties, hooks standard traits, and invokes your standard handle() method, providing a robust integration pattern.
All versions of laravel-simple-sqs with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/queue Version ^8.0|^9.0|^10.0|^11.0|^12.0
aws/aws-sdk-php Version ^3.0