PHPackages                             ipresence/domain\_events - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ipresence/domain\_events

ActiveLibrary

ipresence/domain\_events
========================

1.2.0(7y ago)018.0kMITPHPPHP ^7.1

Since Jan 17Pushed 7y ago2 watchersCompare

[ Source](https://github.com/iPresence/domain_events)[ Packagist](https://packagist.org/packages/ipresence/domain_events)[ RSS](/packages/ipresence-domain-events/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (5)Used By (0)

Domain Events
=============

[](#domain-events)

[![Build Status](https://camo.githubusercontent.com/ecfb9726704e5a9aac558b8ebc40ff3f55b608c90c4cdfee014d114fd25861bb/68747470733a2f2f7472617669732d63692e6f72672f6950726573656e63652f646f6d61696e5f6576656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/iPresence/domain_events)

A domain event is something that happened on your application that is interesting for the business. With this component you will be able to publish an listen to events really easily.

TL;DR
-----

[](#tldr)

```
# domain_events.yaml
mapping:
  event_name: Namespace/CustomDomainEvent

rabbit:
  host: 127.0.0.1
  port: 5672
  user: guest
  pass: guest

  exchange:
    name: domain-events
    type: direct

  queue:
    name: domain-events-test
    bindings:
      - event_1
      - event_2
```

```
$publisher = PublisherBuilder::create()->withYamlConfig('domain_events.yaml')->build();
$listener = ListenerBuilder::create()->withYamlConfig('domain_events.yaml')->build();

$publisher->add($yourDomainEvent);
$publisher->publish();

$listener->subscribe(new YourDomainEventSubscriber());
$listener->listen();
```

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Flow](#flow)
- [Configuration](#configuration)
- [Requirements](#requirements)
- [Compatibility](#compatibility)
- [Development environment](#development-environment)

Installation
------------

[](#installation)

Require the package as usual

```
composer require ipresence/domain_events
```

To use [RabbitMQ](https://github.com/php-amqplib/php-amqplib) as a queue (the default option), you have to **require it manually**

```
composer require php-amqplib/php-amqplib "^2.6"
```

Usage
-----

[](#usage)

### Manually

[](#manually)

Publishing

```
$publisher = PublisherBuilder::create()
    ->withYamlConfig('domain_events.yaml')
    ->build();

$publisher->add($yourDomainEvent);
$publisher->publish();
```

Listening

```
$listener = ListenerBuilder::create()
    ->withYamlConfig('domain_events.yaml')
    ->build();

$listener->subscribe(new YourDomainEventSubscriber());
$listener->listen();
```

### Symfony

[](#symfony)

If you are using symfony, the easiest wait is to use it as a bundle, you just need to add `IPresence\DomainEvents\Symfony\DomainEventsBundle::class` in your bundles.php file and this will load the `domain_events.yaml` config located inside `config/packages/`. At that point you'll have the Publisher and Listener defined in the dependency injection container ready to be used.

Flow
----

[](#flow)

The currently, we just have RabbitMQ. Here you can see the flowchart: [![flow](docs/flow.png)](docs/flow.png)

This library is not only going to create a publisher and listener for you, it will also create the RabbitMQ exchanges and queues so you don't need to worry about that part.

Configuration
-------------

[](#configuration)

The library allows to build the publisher and the listener from a set configuration values. For example:

```
# domain_events.yaml
domain_events:
  mapping:
    event_name: Namespace/CustomDomainEvent

  provider:
      rabbit:
        host: 127.0.0.1
        port: 5672
        user: guest
        pass: guest
        vhost: /

        exchange:
          name: domain-events
          type: direct
          passive: false
          durable: true
          autoDelete: false

        queue:
          name: domain-events-test
          bindings:
            - event_1
            - event_2
          passive: false
          durable: true
          exclusive: false
          autoDelete: false

        consumer:
          noLocal: false
          noAck: false
          exclusive: false
          noWait: false
```

- `mapping`: A key-value array with the mapping between domain event names and classes. This is used to deserialize from JSON to PHP objects
- `provider` (**required**): A key-value array with the provider to be used

#### Rabbit configuration values

[](#rabbit-configuration-values)

- `host`: RabbitMQ host (defaults to localhost)
- `port`: RabbitMQ port defaults to (5672)
- `user` (**required**): RabbitMQ user
- `pass` (**required**): RabbitMQ pass
- `vhost`: RabbitMQ vhost to use (defaults to /)
- `exchange`: A key-value array with the exchange configuration
- `queue`: A key-value array with the queue configuration
- `consumer`: A key-value array with the consumer configuration

##### Exchange configuration values

[](#exchange-configuration-values)

- `name` (**required**): Name of the exchange where the domain events will be published
- `type`: Type of exchange (defaults to direct)
- `passive`: Will fail if the exchange is already created (defaults to false)
- `durable`: Durable exchange will remain active when server restarts (defaults to true)
- `autoDelete`: Exchange will be deleted when all queues have finished using it (defaults to false)

##### Queue configuration values

[](#queue-configuration-values)

- `name` (**required**): Name of the queue where the domain events will be stored before being consumed
- `bindings`: List of domain event names that this queue will store (events that are not in this list will be ignored)
- `passive`: Will fail if the queue is already created (defaults to false)
- `durable`: Durable queue will remain active when server restarts (defaults to true)
- `exclusive`: The queue will be only accessible from the current connection (defaults to false)
- `autoDelete`: Queue will be deleted when all consumers have finished using it (defaults to false)

##### Consumer configuration values

[](#consumer-configuration-values)

- `noLocal`: RabbitMQ will not send messages to the connection that published them (defaults to false)
- `noAck`: When message will be automatically acknowledged once consumed (defaults to false)
- `exclusive`: Request exclusive consumer access, meaning only this consumer can access the queue (defaults to false)
- `noWait`: RabbitMQ will not respond to the method. The client should not wait for a reply method (defaults to false)

### Requirements

[](#requirements)

- `php >=7.1`
- `psr/log ^1.0`
- `ramsey/uuid ^3.8`
- `ipresence/monitoring ^1.0`

The library allows to use different queues, an adapter for RabbitMQ is included in the library but you must require the dependency manually

```
composer require php-amqplib/php-amqplib "^2.6"
```

#### Logging

[](#logging)

Do you want to know why you can't send a domain event or why you are not receiving it? No problem, the library accepts any [Psr-3 logger](http://www.php-fig.org/psr/psr-3/) logger implementation (like [Monolog](https://github.com/Seldaek/monolog)) to write debug and error messages. You just need to tell the builder that you want to use it.

```
ListenerBuilder::create()
    ->withYamlConfig('domain_events.yaml')
    ->withLogger($psr3Logger)
    ->build();
```

#### Monitoring

[](#monitoring)

Do you want to know how many domain events are been published or consumed? No problem, the library accepts any monitor that implements this [interface](https://github.com/iPresence/monitoring/blob/master/src/Monitor.php). You just need to tell the builder that you want to use it.

```
ListenerBuilder::create()
    ->withYamlConfig('domain_events.yaml')
    ->withMonitor($monitor)
    ->build();
```

### Compatibility

[](#compatibility)

This library has been tested with the following PHP versions and setups

PHPphp-amqplib/php-amqplibresult7.12.8.1✅7.22.8.1✅7.32.8.1✅Development environment
-----------------------

[](#development-environment)

To build the test environment you'll need docker and docker-compose installed:

```
make dev

```

### Running the tests

[](#running-the-tests)

```
make test
```

You can run the tests only for a php version like this

```
make unit PHP_VERSION=7.3
```

### Stop the environment

[](#stop-the-environment)

```
make nodev

```

### Delete the environment

[](#delete-the-environment)

You can delete the docker images for a total clean-up

```
 make nodev IMAGES=true
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Total

3

Last Release

2584d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a59f352cddc3f357866652ab4f82a28581f2a3b84336fd1442a50e1aecb5e38?d=identicon)[qu1m](/maintainers/qu1m)

---

Top Contributors

[![hmoragrega](https://avatars.githubusercontent.com/u/3494001?v=4)](https://github.com/hmoragrega "hmoragrega (9 commits)")[![ussrlongbow](https://avatars.githubusercontent.com/u/1707164?v=4)](https://github.com/ussrlongbow "ussrlongbow (1 commits)")

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/ipresence-domain-events/health.svg)

```
[![Health](https://phpackages.com/badges/ipresence-domain-events/health.svg)](https://phpackages.com/packages/ipresence-domain-events)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M16.9k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laravel/nightwatch

The official Laravel Nightwatch package.

3486.1M13](/packages/laravel-nightwatch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
