gilbitron/sqsd
Composer 安装命令:
composer require gilbitron/sqsd
包简介
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
README 文档
README
While testing a Laravel app running on AWS Elastic Beanstalk I came across the situation where I wanted to be able to test how my app would handle interacting with the worker tier SQS daemon (sqsd) on my local machine. As sqsd is not open source there is currently no official way of doing this.
This project (inspired by others) is an attempt to replicate the functionality of sqsd in PHP for local testing purposes. Note that his library has no dependency on Laravel and can be used to test any kind of app.
Description
The Laravel queue worker operates by polling a queue for jobs and then runs them inline (as the queue worker is part of the application). As sqsd is completely separate from any application it works in a different way so that any application can be designed to work with it.
Sqsd works by polling a SQS queue for jobs and then POST's them to an endpoint specified in your Elastic Beanstalk worker environment settings (default is http://localhost/). If a job fails for any reason, then the job is sent to what is called a Dead Letter Queue for manual processing.
Another aspect of sqsd is that it can read a cron.yaml file in the root of your application which specifies periodic tasks that can be run on a schedule. Sqsd will send a job to the queue every time the schedule is triggered. These jobs will then be processed by sqsd like normal, but will be POSTed to the path specified in the cron.yaml with some extra headers.
Requirements
- PHP >= 5.5.0
- Composer
Install & Usage
- Clone this repo
- Copy
.env.exampleto.envand fill in the details (see below) - Run
composer install - Run
php ./bin/sqsd.phar work
To install as a composer dependency:
- Run
composer require gilbitron/sqsd - Run
php ./vendor/bin/sqsd.phar work
Note: If your're running sqsd as a composer dependency you will need to set your environment variables via the command line (see below for more info).
Configuration
Configuration is done by either setting environment variables before running sqsd (e.g. export SQS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/123456789) or specifying them in .env.
| Env Variable | Description |
|---|---|
AWS_ACCESS_KEY_ID * |
AWS access key ID with SQS permissions |
AWS_SECRET_ACCESS_KEY * |
AWS secret access key |
SQS_QUEUE_URL * |
The URL of the SQS queue (e.g. https://sqs.us-east-1.amazonaws.com/123456789) |
SQS_QUEUE_NAME * |
The name of the SQS queue |
SQS_QUEUE_REGION * |
The region of the SQS queue (e.g. us-east-1) |
SQS_MAX_MESSAGES |
The maximum number of messages that will be received from the SQS queue at a time (default and max is 10) |
SQS_WAIT_TIME |
The length of time in seconds that sqsd will wait while polling the SQS queue for messages |
SQSD_WORKER_URL |
The URL the worker will POST to (default is http://localhost) |
SQSD_WORKER_PATH |
The path that will be appended to the worker URL (default is /). This is the same as the HTTP Path setting in the Elastic Beanstalk worker environment settings |
SQSD_CRON_PATH |
Absolute path to a cron.yaml which specifies periodic tasks |
SQSD_SLEEP_SECONDS |
The time in seconds sqsd should sleep between checks (default is 1) |
SQSD_STORAGE_PATH |
Path to a writable storage dir (default is /tmp/sqsd) |
Environment variables marked with a * are required for sqsd to work.
Building the Phar
To build Phar file first you need to install Box then run:
box build -v
Laravel Tips
If you're looking for a package that will make Laravel work with sqsd I recommend dusterio/laravel-aws-worker.
If you are using this to test a Laravel app, instead of configuring Supervisor to run the aritsan queue:work command, configure Supervisor to run the sqsd work command.
Contribute
So you want to help out? That's awesome. Here is how you can do it:
If you are submitting a pull request please adhere to the existing coding standards used throughout the code and only submit 1 feature/fix per pull request. Pull requests containing multiple changes will be rejected.
Credits
Sqsd was created by Gilbert Pellegrom from Dev7studios. Released under the MIT license.
gilbitron/sqsd 适用场景与选型建议
gilbitron/sqsd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.63k 次下载、GitHub Stars 达 33, 最近一次更新时间为 2017 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「aws」 「worker」 「sqs」 「daemon」 「sqsd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gilbitron/sqsd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gilbitron/sqsd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gilbitron/sqsd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package that enables support for SQS FIFO Queue
Queue
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
SlimQ Enables You to push jobs to background workers
Elastic Driver for Laravel Scout
An extension to the Amazon SQS client that enables sending and receiving messages up to 2GB via Amazon S3.
统计信息
- 总下载量: 2.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 33
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-27
