/protean:subscriberfrom protean
Defines a Protean subscriber that consumes external broker messages and translates them into domain operations, acting as an anti-corruption layer at the domain boundary.
Ships in protean. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A subscriber consumes messages that another system publishes on a broker stream, and translates each one into an action in this domain. This skill defines subscribers and their options.
| Aspect | Event Handler | Subscriber |
|---|---|---|
| Decorator | @domain.event_handler | @domain.subscriber |
| Message source | Internal event store | External message broker |
| Association | part_of an aggregate or stream_category | stream on a broker |
| Payload type | Typed domain event objects | Raw dict payloads |
| Dispatch | @handle(EventClass) per event type | Single __call__(payload) for all messages |
| Processing config | event_processing | message_processing |
| Use case | React to domain changes within bounded context | Consume messages from external systems |
from protean import Domain
from protean.fields import Decimal, Identifier, String
domain = Domain()
domain.config["message_processing"] = "sync"
@domain.aggregate
class Payment:
order_id: Identifier(required=True)
amount: Decimal(precision=19, scale=4, required=True)
status: String(default="PENDING")
def confirm(self):
self.status = "CONFIRMED"
@domain.subscriber(stream="payment_gateway")
class PaymentConfirmationSubscriber:
def __call__(self, payload: dict) -> None:
order_id = payload["order_id"]
repo = domain.repository_for(Payment)
payment = repo.find_by(order_id=order_id)
payment.confirm()
repo.add(payment)
@domain.subscriber(stream="payment_gateway")__call__(self, payload: dict), not @handle@domain.subscriber(stream="...", broker="my_broker")domain.config["message_processing"] = "sync" (NOT event_processing)| Option | Purpose | Required |
|---|---|---|
stream | Name of the external broker stream to consume | Yes |
broker | Broker name (defaults to "default") | No |
idempotent | Skip a redelivered payload, keyed on its metadata.headers.id (defaults to False) | No |
provider | Database provider for the idempotency marker (defaults to "default") | No |
suppress_checks | Diagnostic codes to suppress for this subscriber | No |
@domain.aggregate
class Order:
status: String(max_length=20, default="PENDING")
tracking_number: String(max_length=50)
def mark_paid(self):
self.status = "PAID"
def mark_shipped(self, tracking_number: str):
self.status = "SHIPPED"
self.tracking_number = tracking_number
@domain.subscriber(stream="payment_gateway")
class PaymentWebhookSubscriber:
def __call__(self, payload: dict) -> None:
if payload["status"] == "SUCCESS":
order = domain.repository_for(Order).get(payload["order_id"])
order.mark_paid()
domain.repository_for(Order).add(order)
@domain.subscriber(stream="shipping_updates", broker="default")
class ShippingUpdateSubscriber:
def __call__(self, payload: dict) -> None:
order = domain.repository_for(Order).get(payload["order_id"])
order.mark_shipped(payload["tracking_number"])
domain.repository_for(Order).add(order)
@domain.aggregate
class Customer:
name: String(required=True)
email: String(required=True)
@domain.command(part_of="Customer")
class RegisterCustomer:
customer_id: Identifier(required=True)
name: String(required=True)
email: String(required=True)
@domain.subscriber(stream="erp_user_events")
class ERPUserSubscriber:
"""Translates external ERP format into domain commands."""
def __call__(self, payload: dict) -> None:
if payload.get("event_type") == "user.created":
data = payload["data"]
command = RegisterCustomer(
customer_id=data["userId"],
name=f"{data['firstName']} {data['lastName']}",
email=data["emailAddress"],
)
domain.process(command)
Override handle_error classmethod for custom error recovery during async processing:
import logging
logger = logging.getLogger(__name__)
@domain.subscriber(stream="inventory_updates")
class InventorySubscriber:
def __call__(self, payload: dict) -> None:
# ... processing logic ...
pass
@classmethod
def handle_error(cls, exc: Exception, message: dict) -> None:
logger.error("Inventory update failed: %s", exc)
# fragment
@domain.subscriber # Wrong! Missing stream
class MySubscriber:
def __call__(self, payload: dict) -> None:
pass
Instead: Always specify stream.
A subscriber with no stream has nothing to consume, so it never registers:
@domain.subscriber raises IncorrectUsageError at class definition time,
with the message "Subscriber MySubscriber needs to be associated with a
stream". check reports the same problem as SUBSCRIBER_NO_STREAMS, which it
can only see in materialized IR that was loaded or hand-edited after the
stream was removed.
event-handler: Compare/contrast: event handlers consume internal domain events, subscribers consume external broker messagesaggregate: Subscribers often load and update aggregates through repositoriescommand: Subscribers commonly translate external messages into domain commandscommand-handler: Subscribers often dispatch commands for processingcheck and resolve what it reportsassets/subscriber_anti_corruption.py (opens in a new tab)assets/subscriber_domain_interaction.py (opens in a new tab)assets/subscriber_error_handling.py (opens in a new tab)assets/subscriber_multiple_streams.py (opens in a new tab)assets/subscriber_simple.py (opens in a new tab)references/anti-corruption-layer.md (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/basic-subscriber.md (opens in a new tab)references/error-handling.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub proteanhq/protean --plugin protean39 skills in this plugin
/add-commandAdd a complete command flow to an existing aggregate. It creates a command class, a FastAPI API endpoint, and a command handler with repository logic. This is the primary workflow for adding write operations to a Protean domain. Use when the user wants to "add a command", "add an action", "add an operation", "expose a write endpoint", "create a command flow", "wire up a POST endpoint", "add a new operation to an aggregate", or describes an action like "I want users to be able to [verb] a [thing]" (e.g., "place an order", "register a user", "cancel a reservation"). This workflow composes the command, command-handler, and api-endpoint element skills./add-domain-service-flowBuild a domain service flow in Protean for business logic that spans two or more aggregates. Domain services are stateless, encapsulate cross-aggregate business rules, and run pre/post invariants for validation. They are used when business logic doesn't naturally belong to a single aggregate. Wire them into command handlers or application services for persistence. Use when the user asks to "add a domain service", "implement cross-aggregate logic", "coordinate multiple aggregates", "add a business operation spanning aggregates", "validate across aggregates", or when they describe scenarios like "placing an order checks inventory and reserves stock", "transferring funds between accounts", "scheduling involves both resource and calendar"./add-eventAdd a complete event flow to an existing aggregate. It creates a domain event, adds or updates an aggregate method that raises the event via self.raise_(), and wires an event handler that processes the event and performs specified side effects (such as syncing state across aggregates, sending notifications, or triggering downstream processes). This is the primary workflow for adding reactive, event-driven behavior to a Protean domain. Use when the user wants to "add an event", "add a domain event", "add a reaction to a state change", "add a side effect", "create an event flow", "wire an event handler", "add event-driven behavior", "react to a state change", "sync aggregates on event", or describes something that happened or should happen (like "when an order is placed, reduce inventory", "after payment is confirmed, send a notification", "when a user registers, create a welcome email", "notify the warehouse when an order ships"). This workflow composes the event, aggregate, and event-handler element skills./add-fieldAdd fields to Protean domain elements (aggregates, entities, value objects). Guides you through selecting the right field type, configuring validations, and placing fields correctly. Use when the user asks to "add a field", "add an attribute", "add a property", "I need to store [data]", "add a new field to [aggregate/entity]", or describes data that needs to be tracked. Covers simple fields, association fields (HasOne, HasMany, ValueObject), field validation, custom validators, and choosing between field types for different use cases./add-read-modelBuild a complete read model in Protean, a projection populated by a projector that reacts to domain events. Covers single-aggregate projections (flattened view of one aggregate), cross-aggregate projections (combining data from multiple aggregates), and choosing between database-backed and cache-backed storage. Use when the user asks to "add a read model", "create a projection with projector", "build a query view", "add a CQRS read side", "create a denormalized view", "build a reporting view", "add a dashboard query model", or when they need to combine data from multiple aggregates into one queryable structure./add-saga-flowBuild a complete saga in Protean using a process manager that coordinates a multi-step flow across several aggregates. The saga reacts to domain events, issues commands to drive each aggregate forward, tracks its own state, and closes on a terminal handler with a compensating path for failures. Use when the user asks to "add a saga", "coordinate a multi-step process", "orchestrate a workflow across aggregates", "manage order fulfillment", "add a process manager flow", "compensate on failure", "roll back a distributed transaction", or when they describe a flow like "reserve stock, take payment, then ship, and undo the reservation if payment fails".Other plugins' skills for the same job