본문으로 건너뛰기
cccskills
무료GitHub에 공개

acc-create-outbox-pattern

Generates Transactional Outbox pattern components for PHP 8.5. Creates OutboxMessage entity, repository, publisher, and processor with unit tests.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Outbox Pattern Generator

Creates Transactional Outbox pattern infrastructure for reliable event publishing.

When to Use

  • Need reliable event publishing across transaction boundaries
  • Prevent message loss if broker is down
  • Ensure exactly-once or at-least-once delivery
  • Maintain consistency between database and message broker

Component Characteristics

OutboxMessage Entity

  • Immutable value object in Domain layer
  • Contains: id, aggregateType, aggregateId, eventType, payload, timestamps
  • Supports reconstitution for persistence
  • Methods: withProcessed(), withRetryIncremented()

OutboxRepository

  • Interface in Domain layer
  • Implementation in Infrastructure layer
  • Methods: save, findUnprocessed, markAsProcessed, incrementRetry, delete

OutboxProcessor

  • Application layer service
  • Polls for unprocessed messages
  • Publishes to message broker
  • Handles failures with retry and dead letter

Console Command

  • Infrastructure layer
  • Runs as daemon or one-shot
  • Configurable batch size and interval

Generation Process

Step 1: Generate Domain Layer

Path: src/Domain/Shared/Outbox/

  1. OutboxMessage.php — Immutable message entity
  2. OutboxRepositoryInterface.php — Repository contract

Step 2: Generate Application Layer

Path: src/Application/Shared/

  1. Port/Output/MessagePublisherInterface.php — Publisher port
  2. Port/Output/DeadLetterRepositoryInterface.php — Dead letter port
  3. Outbox/ProcessingResult.php — Result value object
  4. Outbox/MessageResult.php — Result enum
  5. Outbox/OutboxProcessor.php — Processing service

Step 3: Generate Infrastructure Layer

Path: src/Infrastructure/

  1. Persistence/Doctrine/Repository/DoctrineOutboxRepository.php
  2. Console/OutboxProcessCommand.php
  3. Database migration

Step 4: Generate Tests

  1. tests/Unit/Domain/Shared/Outbox/OutboxMessageTest.php
  2. tests/Unit/Application/Shared/Outbox/OutboxProcessorTest.php

Key Principles

Transactional Consistency

// In UseCase - save outbox message in SAME transaction
$this->connection->transactional(function () use ($order, $event) {
    $this->orderRepository->save($order);
    $this->outboxRepository->save(
        OutboxMessage::create(
            id: Uuid::uuid4()->toString(),
            aggregateType: 'Order',
            aggregateId: $order->id()->toString(),
            eventType: 'order.placed',
            payload: $event->toArray()
        )
    );
});

Retry with Dead Letter

  1. Retry up to MAX_RETRIES times
  2. Exponential backoff between retries
  3. Move to dead letter queue after max retries
  4. Log all failures with context

Message Headers

Include metadata for tracing:

  • message_id, correlation_id, causation_id
  • aggregate_type, aggregate_id
  • created_at

File Placement

LayerPath
Domain Entitysrc/Domain/Shared/Outbox/
Domain Interfacesrc/Domain/Shared/Outbox/
Application Servicesrc/Application/Shared/Outbox/
Application Portsrc/Application/Shared/Port/Output/
Infrastructure Reposrc/Infrastructure/Persistence/Doctrine/Repository/
Infrastructure Consolesrc/Infrastructure/Console/
Unit Teststests/Unit/{Layer}/{Path}/

Naming Conventions

ComponentPatternExample
Entity{Name}OutboxMessage
Repository Interface{Name}RepositoryInterfaceOutboxRepositoryInterface
Repository ImplDoctrine{Name}RepositoryDoctrineOutboxRepository
Service{Name}ProcessorOutboxProcessor
Command{Name}CommandOutboxProcessCommand
Test{ClassName}TestOutboxMessageTest

Quick Template Reference

OutboxMessage

final readonly class OutboxMessage
{
    public static function create(
        string $id,
        string $aggregateType,
        string $aggregateId,
        string $eventType,
        array $payload,
        ?string $correlationId = null,
        ?string $causationId = null
    ): self;

    public function isProcessed(): bool;
    public function isPoisoned(int $maxRetries): bool;
    public function payloadAsArray(): array;
    public function withProcessed(): self;
    public function withRetryIncremented(): self;
}

OutboxRepositoryInterface

interface OutboxRepositoryInterface
{
    public function save(OutboxMessage $message): void;
    public function findUnprocessed(int $limit = 100): array;
    public function markAsProcessed(string $id): void;
    public function incrementRetry(string $id): void;
    public function delete(string $id): void;
}

OutboxProcessor

final readonly class OutboxProcessor
{
    public function process(int $batchSize = 100): ProcessingResult;
}

Usage Example

Saving to Outbox

// In UseCase
$message = OutboxMessage::create(
    id: Uuid::uuid4()->toString(),
    aggregateType: 'Order',
    aggregateId: $order->id()->toString(),
    eventType: 'order.placed',
    payload: [
        'order_id' => $order->id()->toString(),
        'customer_id' => $order->customerId()->toString(),
        'total' => $order->total()->amount(),
    ],
    correlationId: $command->correlationId
);

$this->outboxRepository->save($message);

Console Command

# One-shot processing
php bin/console outbox:process --batch-size=100

# Daemon mode
php bin/console outbox:process --daemon --interval=1000

DI Configuration

# Symfony services.yaml
Domain\Shared\Outbox\OutboxRepositoryInterface:
    alias: Infrastructure\Persistence\Doctrine\Repository\DoctrineOutboxRepository

Application\Shared\Port\Output\MessagePublisherInterface:
    alias: Infrastructure\Messaging\RabbitMq\RabbitMqPublisher

Application\Shared\Outbox\OutboxProcessor:
    arguments:
        $maxRetries: 5

Database Schema

CREATE TABLE outbox_messages (
    id VARCHAR(36) PRIMARY KEY,
    aggregate_type VARCHAR(255) NOT NULL,
    aggregate_id VARCHAR(255) NOT NULL,
    event_type VARCHAR(255) NOT NULL,
    payload JSONB NOT NULL,
    correlation_id VARCHAR(255),
    causation_id VARCHAR(255),
    created_at TIMESTAMP(6) NOT NULL,
    processed_at TIMESTAMP(6),
    retry_count INT NOT NULL DEFAULT 0
);

CREATE INDEX idx_outbox_unprocessed
ON outbox_messages (processed_at, created_at)
WHERE processed_at IS NULL;

References

For complete PHP templates and test examples, see:

  • references/templates.md — All component templates
  • references/tests.md — Unit test examples

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

MikeCheng1208의 스킬 모두 보기

이 스킬의 문제 신고