承接 tetthys/claim-dispatch 相关项目开发

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

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

tetthys/claim-dispatch

Composer 安装命令:

composer require tetthys/claim-dispatch

包简介

Minimal contracts for claim→process→dispatch pipelines, with built-in Laravel adapter.

README 文档

README

Atomic claim-dispatch framework for Laravel
Safely schedule and dispatch jobs from a single action log table.

✨ Features

  • Single table (action_logs) as a durable schedule
  • Atomic claim – prevent duplicate dispatch across workers
  • Processors – type-based mapping from log row → Job
  • Idempotent jobs – designed for safe re-execution
  • Universal publisher – domain-agnostic, higher-order & fluent
  • Publisher Facade – simple static API: Publisher::quick(...)
  • Configurable – add your own processors, rules, and evaluation logic

📦 Installation

composer require tetthys/claim-dispatch

Publish config and migration:

php artisan vendor:publish --tag=claim-dispatch-config
php artisan vendor:publish --tag=claim-dispatch-migrations
php artisan migrate

⚡ Quick Start

1. Define a Processor

Suppose you want to schedule welcome emails. Each log row with type = email.welcome should become a SendWelcomeEmail Job.

<?php
// app/Processors/WelcomeEmailProcessor.php

namespace App\Processors;

use Tetthys\ClaimDispatch\Contracts\LogProcessorInterface;
use Tetthys\ClaimDispatch\Contracts\LogRecordInterface;
use App\Jobs\SendWelcomeEmail;

final class WelcomeEmailProcessor implements LogProcessorInterface
{
    public function supports(string $type): bool
    {
        return $type === 'email.welcome';
    }

    public function toJob(LogRecordInterface $record): object
    {
        $p = $record->getPayload();
        return new SendWelcomeEmail((string) ($p['user_email'] ?? ''));
    }
}

Register it in config/claim-dispatch.php:

'processors' => [
    App\Processors\WelcomeEmailProcessor::class,
],

2. Publish an Action Log

👉 Using the Facade (recommended)

use Publisher;

// One-liner (quick)
Publisher::quick('email.welcome', now()->addMinutes(5), [
    'user_email' => $user->email,
    'user_name'  => $user->name,
], [
    'idempotency' => 'welcome:' . $user->id,
]);

// Higher-order builder
Publisher::publish(function (\Tetthys\ClaimDispatch\Publishing\Draft $d) use ($user) {
    $d->type('email.welcome')
      ->eligibleAt(now()->addMinutes(5))
      ->payload([
          'user_email' => $user->email,
          'user_name'  => $user->name,
      ])
      ->idempotency('welcome:' . $user->id);
});

Facade Publisher is available if you add

'Publisher' => \Tetthys\ClaimDispatch\Laravel\Facades\Publisher::class,

to your config/app.php aliases (or rely on auto-discovery).

3. Run the Scheduler

Add to app/Console/Kernel.php:

protected function schedule(\Illuminate\Console\Scheduling\Schedule $schedule): void
{
    $schedule->command('claim-dispatch:run --limit=1000')->everyMinute();
}

Start a queue worker:

php artisan queue:work

🧩 How It Works

  1. Publish Insert a row into action_logs:

    • type = routing key (e.g. email.welcome)
    • payload = JSON data (email address, etc.)
    • end_at = earliest eligible time
  2. Scheduler Runs every minute (or via cron). Atomically claims rows (end_at <= now() AND claimed_at IS NULL) and dispatches them to processors.

  3. Processor → Job Each processor transforms the record into a Laravel Job. Jobs must be idempotent.

  4. Execution Queue workers run the jobs. After success, the row is marked processed_at.

✅ Example Workflow

  • A new user signs up.
  • The app publishes an email.welcome log with their email and a 5-minute delay.
  • After 5 minutes, the scheduler claims it and dispatches SendWelcomeEmail.
  • The Job sends the email.
  • Even with multiple workers, it is dispatched exactly once.

🔧 Advanced

  • Rules & Gates

    • rules([...]): store declarative predicates in payload (__rules).
    • when(fn ($payload) => ...): only insert if predicate passes.
    • skipIf(fn ($payload) => ...): skip insert if predicate passes.
    • Processors can evaluate __rules as a second guard.
  • Idempotency Provide a stable key with idempotency($key). Prevents duplicate rows for the same logical event.

  • Multiple domains Just add more processors (email.newsletter, report.generate, …).

📖 License

MIT

tetthys/claim-dispatch 适用场景与选型建议

tetthys/claim-dispatch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tetthys/claim-dispatch 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-19