renatomaldonado/laravel-sqs-consume
最新稳定版本:v1.0.1
Composer 安装命令:
composer require renatomaldonado/laravel-sqs-consume
包简介
Consumer of sqs message
README 文档
README
A custom SQS connector for Laravel (or Lumen) that supports many jobs e any message types based in library https://github.com/dusterio/laravel-plain-sqs.
But each job will be responsible for one queue sqs. All will be execute, if message in some queue exists it will be processed.
Dependencies
- PHP >= 7.1.3
- Laravel (or Lumen) >= 7.0
Installation via Composer
To install simply run:
composer require renatomaldonado/laravel-sqs-consume
Usage in Laravel 7
// Add in your config/app.php 'providers' => [ '...', 'Renatomaldonado\LaravelSqsConsume\Provider\LaravelSQSQueueServiceProvider', ];
Usage in Lumen 7
// Add in your bootstrap/app.php $app->register(Renatomaldonado\LaravelSqsConsume\Provider\LumenSQSQueueServiceProvider::class);
Configuration
// Generate standard config file (Laravel only) php artisan vendor:publish --provider="Renatomaldonado\LaravelSqsConsume\Provider\LaravelSQSQueueServiceProvider" // In Lumen, create it manually (see example below) and register it in bootstrap/app.php $app->configure('sqs-consumer');
Edit config/sqs-consumer.php to suit your needs. This config matches SQS queues with handler classes.
return [ /** * Queues array for execute in each job */ 'queues' => ['queue-sqs-name-example', 'queue-sqs-name-example-two'], 'handlers' => [ 'queue-sqs-name-example' => 'your-job', 'queue-sqs-name-example-two' => 'your-job-two', ], 'default-handler' => 'job-default' ];
If queue is not found in 'handlers' array, SQS payload is passed to default handler.
Add sqs-consumer connection to your config/queue.php, eg:
... 'sqs-consumer' => [ 'driver' => 'sqs-consumer', 'key' => env('AWS_KEY', ''), 'secret' => env('AWS_SECRET', ''), 'prefix' => 'https://sqs.ea-northheast-1.amazonaws.com/123456/', 'queue' => 'queue-sqs-name-example', 'region' => 'ea-northheast-1', ], ...
In your .env file, choose sqs-consumer as your new default queue connection:
QUEUE_CONNECTION=sqs-consumer
Receiving from SQS
If a third-party application is creating custom-format JSON messages or any message, just add a handler in the config file and implement a handler class as follows:
use Illuminate\Contracts\Queue\Job as LaravelJob; class ExempleJob extends Job { protected $data; /** * @param LaravelJob $job * @param $data */ public function handle(LaravelJob $job, $data) { // This is incoming JSON payload, already decoded to an array var_dump($data); // Raw JSON payload from SQS, if necessary var_dump($job->getRawBody()); } }
统计信息
- 总下载量: 8.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-24