Create message broker adapter

From dykyi-roman/awesome-claude-code · View interactive version

Create message broker adapter is an AI agent skill from the GitHub repository dykyi-roman/awesome-claude-code. Generates Message Broker Adapter components for PHP 8.4. Creates unified broker interface with RabbitMQ, Kafka, SQS adapters, message serialization, and unit tests.

How to use this skill

Skill file

Message Broker Adapter Generator

Creates unified message broker abstraction with adapter implementations for multiple broker technologies.

When to Use

| Scenario | Example |

|----------|---------|

| Broker abstraction | Switch between RabbitMQ/Kafka/SQS without code changes |

| Multi-broker support | Different brokers for different bounded contexts |

| Testing isolation | InMemory adapter for tests |

| Migration path | Gradual migration from one broker to another |

| Vendor independence | Avoid lock-in to specific message broker |

Component Characteristics

MessageBrokerInterface

Message

MessageSerializerInterface

RabbitMqAdapter

KafkaAdapter

SqsAdapter

InMemoryAdapter


Generation Process

Step 1: Analyze Request

Determine:

Step 2: Generate Core Components

  1. Domain Layer (src/Domain/Shared/Messaging/)
  1. Infrastructure Layer (src/Infrastructure/Messaging/)
  1. Tests

File Placement

| Layer | Path |

|-------|------|

| Domain Types | src/Domain/Shared/Messaging/ |

| Infrastructure | src/Infrastructure/Messaging/ |

| Broker Adapters | src/Infrastructure/Messaging/{Broker}/ |

| Unit Tests | tests/Unit/{Layer}/{Path}/ |


Naming Conventions

| Component | Pattern | Example |

|-----------|---------|---------|

| Interface | MessageBrokerInterface | MessageBrokerInterface |

| Message VO | Message | Message |

| Adapter | {Broker}Adapter | RabbitMqAdapter |

| Serializer | {Format}MessageSerializer | JsonMessageSerializer |

| Factory | MessageBrokerFactory | MessageBrokerFactory |

| Test | {ClassName}Test | RabbitMqAdapterTest |


Quick Template Reference

MessageBrokerInterface

interface MessageBrokerInterface
{
    public function publish(Message $message, string $routingKey = ''): void;
    public function consume(string $queue, callable $handler): void;
    public function acknowledge(Message $message): void;
    public function reject(Message $message, bool $requeue = false): void;
}

Message

final readonly class Message
{
    public function __construct(
        public MessageId $id,
        public string $body,
        public string $routingKey = '',
        public array $headers = [],
        public ?string $correlationId = null,
        public ?string $contentType = 'application/json',
        public ?\DateTimeImmutable $timestamp = null,
    ) {}

    public static function create(string $body, string $routingKey = '', array $headers = []): self;
    public function withHeader(string $key, string $value): self;
    public function withCorrelationId(string $correlationId): self;
}

Usage Example

// Publish
$message = Message::create(
    body: json_encode(['order_id' => $orderId, 'total' => $total]),
    routingKey: 'orders.created'
);
$broker->publish($message);

// Consume
$broker->consume('order_processing', function (Message $message) use ($handler) {
    $handler->handle($message);
    $this->broker->acknowledge($message);
});

DI Configuration

Domain\Shared\Messaging\MessageBrokerInterface:
    factory: ['@Infrastructure\Messaging\MessageBrokerFactory', 'create']
    arguments:
        $driver: '%env(MESSAGE_BROKER_DRIVER)%'

References

For complete PHP templates and test examples, see:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.