Loading...
Loading...
Compare original and translation side by side
| Cas | Async ? |
|---|---|
| Envoi d'email transactionnel | ✅ |
| Génération PDF / export CSV | ✅ |
| Appel API tierce > 200 ms | ✅ |
| Traitement batch nocturne | ✅ |
| Lecture base de données triviale | ❌ |
| 场景 | 是否异步? |
|---|---|
| 发送事务性邮件 | ✅ |
| 生成PDF / 导出CSV | ✅ |
| 调用第三方API耗时>200毫秒 | ✅ |
| 夜间批量处理 | ✅ |
| 简单数据库查询 | ❌ |
| Stack | Framework | Notes |
|---|---|---|
| Symfony | Symfony Messenger | Transport AMQP, Redis, Doctrine ; supports Stamps |
| Laravel | Laravel Queue (Horizon en prod) | Backed by Redis ou SQS ; supervision native |
| PHP framework-agnostic | Ecotone | DDD, sagas, scheduler, messaging unifié |
| Node.js | BullMQ ou RabbitMQ | Redis-backed avec dashboard |
| 技术栈 | 框架 | 说明 |
|---|---|---|
| Symfony | Symfony Messenger | 支持AMQP、Redis、Doctrine传输;支持Stamps机制 |
| Laravel | Laravel Queue(生产环境搭配Horizon) | 基于Redis或SQS;原生支持监控 |
| 无框架PHP | Ecotone | 支持领域驱动设计(DDD)、Sagas、调度器、统一消息传递 |
| Node.js | BullMQ 或 RabbitMQ | 基于Redis,附带仪表盘 |
// Message (immutable DTO)
final class SendWelcomeEmail
{
public function __construct(public readonly string $userId) {}
}
// Handler
final class SendWelcomeEmailHandler
{
public function __invoke(SendWelcomeEmail $message): void
{
// Idempotency check
if ($this->emailLog->wasSent($message->userId, 'welcome')) {
return;
}
$this->mailer->sendWelcome($message->userId);
$this->emailLog->record($message->userId, 'welcome');
}
}
// Dispatch (controller)
$this->bus->dispatch(new SendWelcomeEmail($user->id));// Message (immutable DTO)
final class SendWelcomeEmail
{
public function __construct(public readonly string $userId) {}
}
// Handler
final class SendWelcomeEmailHandler
{
public function __invoke(SendWelcomeEmail $message): void
{
// Idempotency check
if ($this->emailLog->wasSent($message->userId, 'welcome')) {
return;
}
$this->mailer->sendWelcome($message->userId);
$this->emailLog->record($message->userId, 'welcome');
}
}
// Dispatch (controller)
$this->bus->dispatch(new SendWelcomeEmail($user->id));try { ... } catch (\Throwable) { /* swallow */ }try { ... } catch (\Throwable) { /* swallow */ }Détails complets, patterns Laravel/Ecotone, exemples de configuration, observabilité OpenTelemetry, lifecycle events, checklists par phase : voir.@.claude/skills/async/REFERENCE.md
完整细节、Laravel/Ecotone实现模式、配置示例、OpenTelemetry可观测性、生命周期事件、各阶段检查清单:详见。@.claude/skills/async/REFERENCE.md