shipsaas/safe-dispatcher
Composer 安装命令:
composer require shipsaas/safe-dispatcher
包简介
Ensure your Queue msg is tracked and retryable when failed to dispatch.
关键字:
README 文档
README
For Laravel, it has the Queues feature, all cool and easy to use, right?
But what if it fails to dispatch a job? Then you have no idea for:
- What was the data inside the msg?
- What was the error? Traces?
- How to resend the Queue msg with minimal effort?
Then it will cost you a lot of time to check the log, sentry issues, create retry command,... Awful, IKR?
Worries no more, SafeDispatcher got your back. Check out how it works below.
Documentation:
How SafeDispatcher works?
SafeDispatcher will:
- Store the failed to dispatch msgs.
- Retry them on demand.
- You can even change the connection driver or the name on retry.
- Would really come in handy when you have a
SQSException(size > 256kb), then you can resend using redis/database driver.
- Would really come in handy when you have a
- Ensure that your processing/flow is still working properly (no 500 server error from HTTP or exceptions from queue worker).
- Super useful & helpful for mission-critical apps.
Requirements
- Laravel 9+ & 10+
- PHP 8.1 & 8.2
Installation
composer require shipsaas/safe-dispatcher
Usage
Dependency Injection
use SaasSafeDispatcher\Bus\SafeDispatcher; class RegisterService { public function __construct(public SafeDispatcher $dispatcher) {} public function register(): void { $user = User::create(); $job = new SendEmailToRegisteredUser($user); $this->dispatcher->dispatch($job); } }
Use Trait for your Job
use SaasSafeDispatcher\Traits\SafeDispatchable; class SendEmailToRegisteredUser implements ShouldQueue { use SafeDispatchable; } SendEmailToRegisteredUser::safeDispatch($user);
Quick Helper Functions
safeDispatch(new SendEmailToRegisteredUser($user)); safeDispatch(() => echo('Hello')); safeDispatchSync(new SendEmailToRegisteredUser($user));
Cover Queue Facade (v1.2.0+)
use SaasSafeDispatcher\Services\SafeQueue; SafeQueue::prepareFor(new Job()) ->push('high'); # Push to "high" queue name
Learn more Cover Queue Facade
Notes
- SafeDispatcher hasn't supported with batching & chaining.
- Alternatively, you can do normal
::safeDispatchand after finish your job, dispatch another,...
- Alternatively, you can do normal
- SafeDispatcher considers the
syncQueue as a Queue Msg.- Therefore, if the handling fails, Queue Msg will be stored too.
- SafeDispatcher ships some helpful APIs too, check it out: APIs
Tests
SafeDispatcher is not only have normal Unit Testing but also Integration Test (interacting with MySQL for DB and Redis for Queue).
We're planning to add other queue drivers too (database or SQS).
To run the test, hit this:
composer test
Contribute to the project
- All changes must follow PSR-1 / PSR-12 coding conventions.
- Unit testing is a must, cover things as much as you can.
Maintainers & Contributors
- Seth Phat
Join me 😉
This library is useful?
Thank you, please give it a ⭐️⭐️⭐️ to support the project.
Don't forget to share with your friends & colleagues 🚀
License
Copyright © by ShipSaaS 2023 - Under MIT License.
shipsaas/safe-dispatcher 适用场景与选型建议
shipsaas/safe-dispatcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 30, 最近一次更新时间为 2023 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel library」 「laravel safe dispatcher」 「laravel safe dispatch ensure your Queue Job Msgs are totally tracked and resendable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shipsaas/safe-dispatcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shipsaas/safe-dispatcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shipsaas/safe-dispatcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package provides type-safe extension of the laravel collection, forcing a single type of object.
Inbox pattern process implementation for your Laravel Applications
A type safe service, which maps raw data structures onto objects the >= PHP 8 way.
Core library that defines common interfaces used by the rest of the intahwebz..
Symfony Bundle for Google Safe Browsing
Amqp classes
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 30
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-14
