Download the PHP package ipresence/domain_events without Composer
On this page you can find all versions of the php package ipresence/domain_events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package domain_events
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
Table of contents
- Installation
- Usage
- Flow
- Configuration
- Requirements
- Compatibility
- Development environment
Installation
Require the package as usual
To use RabbitMQ as a queue (the default option), you have to require it manually
Usage
Manually
Publishing
Listening
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
The currently, we just have RabbitMQ. Here you can see the flowchart:
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
The library allows to build the publisher and the listener from a set configuration values. For example:
mapping
: A key-value array with the mapping between domain event names and classes. This is used to deserialize from JSON to PHP objectsprovider
(required): A key-value array with the provider to be used
Rabbit configuration values
host
: RabbitMQ host (defaults to localhost)port
: RabbitMQ port defaults to (5672)user
(required): RabbitMQ userpass
(required): RabbitMQ passvhost
: RabbitMQ vhost to use (defaults to /)exchange
: A key-value array with the exchange configurationqueue
: A key-value array with the queue configurationconsumer
: A key-value array with the consumer configuration
Exchange configuration values
name
(required): Name of the exchange where the domain events will be publishedtype
: 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
name
(required): Name of the queue where the domain events will be stored before being consumedbindings
: 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
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
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
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 logger implementation (like Monolog) to write debug and error messages. You just need to tell the builder that you want to use it.
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. You just need to tell the builder that you want to use it.
Compatibility
This library has been tested with the following PHP versions and setups
PHP | php-amqplib/php-amqplib | result |
---|---|---|
7.1 | 2.8.1 | :white_check_mark: |
7.2 | 2.8.1 | :white_check_mark: |
7.3 | 2.8.1 | :white_check_mark: |
Development environment
To build the test environment you'll need docker and docker-compose installed:
Running the tests
You can run the tests only for a php version like this
Stop the environment
Delete the environment
You can delete the docker images for a total clean-up
All versions of domain_events with dependencies
ext-json Version *
psr/log Version ^1.0
ramsey/uuid Version ^3.8
ipresence/monitoring Version ^1.0