create-idempotent-consumer
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-idempotent-consumer":https://skillpi.com/zh/skills/deepskill-95e2e3f84529018a7013b1487df069b4eb8d81b1668f986b4824ad86c82ae0c1。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为 PHP 8.4 生成幂等消费者组件,包含幂等性密钥管理、存储后端、中间件实现以及单元测试以支持消息去重基础设施。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: create-idempotent-consumer
description: Generates Idempotent Consumer components for PHP 8.4. Creates message deduplication infrastructure with idempotency key management, storage backends, middleware, and unit tests.Idempotent Consumer Generator
Creates Idempotent Consumer pattern infrastructure for exactly-once message processing guarantees.
When to Use
| Scenario | Example |
|---|---|
| Payment processing | Prevent double charges on message replay |
| Inventory updates | Avoid duplicate stock deductions |
| Event handlers | Process domain events exactly once |
| Webhook processing | Handle duplicate webhook deliveries |
| Message queue consumers | Deduplicate redelivered messages |
Component Characteristics
IdempotencyKey
- Value object combining messageId + handlerName
- Deterministic key generation
- Immutable with toString() representation
IdempotencyStoreInterface
- Application layer port
- has(IdempotencyKey): bool — check if already processed
- mark(IdempotencyKey, DateTimeImmutable ttl): void — mark as processed
- remove(IdempotencyKey): void — remove entry (for reprocessing)
DatabaseIdempotencyStore
- PDO-based implementation
- TTL-based automatic cleanup
- Unique constraint prevents race conditions
RedisIdempotencyStore
- Redis SETNX-based implementation
- TTL via Redis EXPIRE
- Atomic check-and-set
IdempotentConsumerMiddleware
- Wraps message handler
- Checks idempotency before processing
- Marks as processed after success
- Returns ProcessingResult enum
ProcessingResult
- Enum: Processed, Duplicate, Failed
- Includes original result data on success
- Includes reason on duplicate/failure
Generation Process
Step 1: Analyze Request
Determine:
- Storage backend (Database, Redis, or both)
- TTL for idempotency keys (default: 7 days)
- Integration point (middleware, decorator, manual)
Step 2: Generate Core Components
-
Domain Layer (
src/Domain/Shared/Idempotency/)IdempotencyKey.php— Key value objectProcessingResult.php— Result value object with statusProcessingStatus.php— Status enum (Processed/Duplicate/Failed)
-
Application Layer (
src/Application/Shared/Idempotency/)IdempotencyStoreInterface.php— Storage portIdempotentConsumerMiddleware.php— Middleware wrapper
-
Infrastructure Layer (
src/Infrastructure/Idempotency/)DatabaseIdempotencyStore.php— PDO implementationRedisIdempotencyStore.php— Redis implementation- Database migration
-
Tests
IdempotencyKeyTest.phpProcessingResultTest.phpIdempotentConsumerMiddlewareTest.phpDatabaseIdempotencyStoreTest.php
File Placement
| Layer | Path |
|---|---|
| Domain Types | src/Domain/Shared/Idempotency/ |
| Application Port | src/Application/Shared/Idempotency/ |
| Infrastructure | src/Infrastructure/Idempotency/ |
| Unit Tests | tests/Unit/{Layer}/{Path}/ |
Key Principles
Idempotency Strategy
- Generate deterministic key from message ID + handler name
- Check store BEFORE processing
- Mark as processed AFTER successful handling
- Use database unique constraint as safety net
- TTL cleanup prevents unbounded growth
Race Condition Handling
- Use INSERT ... ON CONFLICT (database)
- Use SETNX (Redis)
- If duplicate detected mid-processing, return Duplicate result
TTL Management
- Default TTL: 7 days (configurable)
- Cleanup via cron/scheduled command
- Redis handles TTL automatically via EXPIRE
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Key VO | IdempotencyKey |
IdempotencyKey |
| Result VO | ProcessingResult |
ProcessingResult |
| Status Enum | ProcessingStatus |
ProcessingStatus |
| Store Interface | IdempotencyStoreInterface |
IdempotencyStoreInterface |
| DB Store | DatabaseIdempotencyStore |
DatabaseIdempotencyStore |
| Redis Store | RedisIdempotencyStore |
RedisIdempotencyStore |
| Middleware | IdempotentConsumerMiddleware |
IdempotentConsumerMiddleware |
| Test | {ClassName}Test |
IdempotencyKeyTest |
Quick Template Reference
IdempotencyKey
final readonly class IdempotencyKey
{
public function __construct(
public string $messageId,
public string $handlerName,
) {}
public static function fromMessage(string $messageId, string $handlerName): self;
public function toString(): string;
public function equals(self $other): bool;
}
IdempotencyStoreInterface
interface IdempotencyStoreInterface
{
public function has(IdempotencyKey $key): bool;
public function mark(IdempotencyKey $key, \DateTimeImmutable $expiresAt): void;
public function remove(IdempotencyKey $key): void;
}
Usage
$middleware = new IdempotentConsumerMiddleware($store);
$result = $middleware->process(
key: IdempotencyKey::fromMessage($message->id, 'handle_payment'),
handler: fn() => $paymentHandler->handle($message),
ttl: new \DateTimeImmutable('+7 days')
);
match ($result->status) {
ProcessingStatus::Processed => $logger->info('Processed'),
ProcessingStatus::Duplicate => $logger->info('Skipped duplicate'),
ProcessingStatus::Failed => $logger->error('Failed', ['error' => $result->error]),
};
Database Schema
CREATE TABLE idempotency_keys (
key VARCHAR(255) PRIMARY KEY,
handler_name VARCHAR(255) NOT NULL,
processed_at TIMESTAMP(6) NOT NULL,
expires_at TIMESTAMP(6) NOT NULL
);
CREATE INDEX idx_idempotency_expires ON idempotency_keys (expires_at);
References
For complete PHP templates and test examples, see:
references/templates.md— All component templatesreferences/examples.md— Payment handler example and unit tests
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 解决消息去重、防止重复处理等实际业务痛点
- 适用于支付、库存、事件处理等高频场景
- 提供完整的幂等消费者基础设施
亮点
- description 明确描述功能,关键词精准
- 边界清晰,覆盖合理
亮点
- 文档结构完整,章节清晰
- 包含端到端示例和完整模板
- frontmatter 完整,命名规范明确
亮点
- 组件设计合理,可靠性机制完善
- 包含 TTL 管理、竞态条件处理、数据库约束
- 提供 Database 和 Redis 两种存储后端实现
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。