comuu / contracts
Shared event contracts and Messenger serializer for Comuu microservices.
Requires
- php: >=8.3
- symfony/amqp-messenger: ^7.0
- symfony/messenger: ^7.0
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is not auto-updated.
Last update: 2026-05-19 13:41:28 UTC
README
Shared event contracts for inter-service communication across Comuu microservices (compte, intervention, location, …).
Events are dispatched via Symfony Messenger over a RabbitMQ topic exchange named
comuu.events. Each event has a stable string type() used as the AMQP routing
key (e.g. user.created, organization.updated).
Install
Add the package via Composer. While not yet published to a registry, use a path or VCS repository:
// composer.json
{
"repositories": [
{ "type": "path", "url": "../comuu-contracts" }
],
"require": {
"comuu/contracts": "@dev"
}
}
Usage — publisher
use Comuu\Contracts\Event\UserCreatedEvent;
$bus->dispatch(new UserCreatedEvent(
uuid: $user->getId()->toRfc4122(),
logtoId: $user->getLogtoId(),
email: $user->getEmail(),
firstName: $user->getFirstName(),
lastName: $user->getLastName(),
phone: $user->getPhone(),
accountType: $user->getAccountType()->value,
roles: $user->getRoles(),
occurredAt: (new \DateTimeImmutable())->format(\DateTimeInterface::ATOM),
));
Usage — consumer
Register the serializer with the local type-map:
# config/services.yaml
services:
Comuu\Contracts\Messaging\Serializer\DomainEventSerializer:
arguments:
$typeMap:
'user.created': Comuu\Contracts\Event\UserCreatedEvent
'user.updated': Comuu\Contracts\Event\UserUpdatedEvent
'user.deleted': Comuu\Contracts\Event\UserDeletedEvent
'organization.created': Comuu\Contracts\Event\OrganizationCreatedEvent
'organization.updated': Comuu\Contracts\Event\OrganizationUpdatedEvent
'organization.deleted': Comuu\Contracts\Event\OrganizationDeletedEvent
# config/packages/messenger.yaml
framework:
messenger:
transports:
account_events:
dsn: '%env(MESSENGER_AMQP_DSN)%'
serializer: Comuu\Contracts\Messaging\Serializer\DomainEventSerializer
options:
exchange:
name: comuu.events
type: topic
queues:
intervention.account_events:
binding_keys: ['user.*', 'organization.*']
Then write handlers in your app (#[AsMessageHandler]) that take a
Comuu\Contracts\Event\* event as their argument.
Wire format
{
"type": "user.created",
"payload": { "uuid": "…", "logtoId": "…", "email": "…", … }
}
AMQP headers: Content-Type: application/json, x-event-type: <type>.
AMQP routing key: <type> (so topic-exchange bindings match on it).