承接 sobhanatar/idempotent 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sobhanatar/idempotent

Composer 安装命令:

composer require sobhanatar/idempotent

包简介

Idempotent Package for Laravel

README 文档

README

Idempotent package provides idempotency for your laravel package. However, in its current state, maybe not extendable to different requirements and can be used as a sample of doing so. Moreover, this package will be updated, in attempt to giving more control over various aspects of it.

Installation

To get started, install the Idempotent package via the Composer package manager:

$ composer require sobhanatar/idempotent

Idempotent service provider registers its own config, language, and database migration file, so you need to export them

$ php artisan vendor:publish --provider="Sobhanatar\Idempotent\IdempotentServiceProvider"

Note: If you don't want to use mysql database as shared memory, you can publish config, and language file using following command:

$ php artisan vendor:publish --tag=idempotent-config --tag=idempotent-language

Deploying Idempotent

To use idempotent package, you need set the options as per the need of your service in configuration and language files. The configuration file is self-documented so that you can find your way through.

The next step is deciding on how you want to control the idempotency of your service. Idempotent package provides two middlewares that can help you achieve the idempotency; IdempotentHeader, and VerifyIdempotent. Don't forget to register the middleware in Kernel.php.

IdempotentHeader

IdempotentHeader makes an idempotent key/hash based on the entity's configurations and put it in the header of request. The assumption in this middleware is that the developer will remain responsible for the logic of using the idempotent header.

VerifyIdempotent

VerifyIdempotent handles all the required steps for making an endpoint idempotent. The steps are as follows:

  1. Get the entity configuration
  2. Create an idempotent key/hash based on the entity's configurations.
  3. Check if the idempotent key/hash exists in the selected storage.
  4. If it doesn't exist:
    1. A new record with the status of progress be created with the entity's timeout, and it continues to the logic of the service
    2. When code execution has finished, the response to the client updates the status and response of the cache.
  5. If it exists:
    1. If the status is done or fail, then the response will be read from storage and replied to the user.
    2. If the status is progress, the message in idempotent language file for that entity will be return as response to the user.

Note: Make sure to use any of two middlewares to only those routes that you want to be idempotent, and not all the routes.

Purging Idempotent Keys/Hashes

If you use mysql as the storage, it's important to purge the expired keys/hashes. Idempotent included idempotent:purge Artisan command can do this for you.

# Purge expired keys/hashes
$ php artisan idempotent:purge --entity=my-idempotent-endpoint

You may also configure a scheduled job in your application's App\Console\Kernel class to automatically prune your tokens on a schedule:

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('idempotent:purge')->hourly();
}

Under the hood

This package is relied on php-lock/lock for locking mechanism and also spatie/async for testing the locking mechanism.

Testing

$ composer test

Contributing

Thank you for considering contributing to Idempotent! You can read the contribution guide here.

Security

If you discover any security-related issues, please email sobhanattar@gmail.com instead of using the issue tracker.

Credits

License

Idempotent is open-sourced software licensed under the MIT license.

sobhanatar/idempotent 适用场景与选型建议

sobhanatar/idempotent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 495 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「idempotency」 「idempotent」 「Idempotent-request」 「Idempotent-Laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sobhanatar/idempotent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sobhanatar/idempotent 我们能提供哪些服务?
定制开发 / 二次开发

基于 sobhanatar/idempotent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 495
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-08