/broadway-bundle

Symfony bundle for broadway/broadway

Primary LanguagePHPMIT LicenseMIT

Broadway Bundle

Symfony bundle to integrate Broadway into your Symfony application.

Note: this bundle is far from complete. Please let us know (or send a pull request) if you miss any configuration options, etc!

Usage

Register the bundle in your application kernel:

$bundles = array(
    // ..
    new Broadway\Bundle\BroadwayBundle\BroadwayBundle(),
);

Note: in order to use the bundle you need some additional dependencies. See the suggest key of the composer.json file.

Services

Once enabled the bundle will expose several services, such as:

  • broadway.command_handling.command_bus command bus to inject if you use commands
  • broadway.event_store alias to the active event store
  • broadway.uuid.generator active uuid generator

Event Store

To generate the mysql schema for the event store use the following command

bin/console broadway:event-store:schema:init

The schema can be dropped using

bin/console broadway:event-store:schema:drop

Tags

The bundle provides several tags to use in your service configuration.

Domain event listeners

Register listeners (such as projectors) that respond and act on domain events:

<tag name="broadway.domain.event_listener" />

Event listeners

For example an event listener that collects successfully executed commands:

<tag name="broadway.event_listener"
    event="broadway.command_handling.command_success"
    method="onCommandHandlingSuccess" />

Metadata enrichers

It is possible to add additional metadata to persisted events. This is useful for recording extra contextual (auditing) data such as the currently logged in user, an ip address or some request token.

<tag name="broadway.metadata_enricher" />

Sagas

Register sagas using the broadway.saga service tag:

<service class="ReservationSaga">
    <argument type="service" id="broadway.command_handling.command_bus" />
    <argument type="service" id="broadway.uuid.generator" />
    <tag name="broadway.saga" type="reservation" />
</service>

Configuration

There are some basic configuration options available at this point. The options are mostly targeted on providing different setups based on production or testing usage.

Note: at this moment the bundle will always use the default doctrine database connection for the event store

broadway:
    event_store:
        dbal:
            enabled:          true
            table:            events
            use_binary:       false # If you want to use UUIDs to be stored as BINARY(16), required DBAL >= 2.5.0
    command_handling:
        logger:               false # If you want to log every command handled, provide the logger's service id here (e.g. "logger")
    saga:
        repository:           ~ # One of "in_memory"; "mongodb"
    read_model:
        repository:           ~ # One of "in_memory"; "elasticsearch"
        elasticsearch:
            hosts:
                # Default:
                - localhost:9200
    serializer:
        payload:              ~ # default: broadway.simple_interface_serializer
        readmodel:            ~ # default: broadway.simple_interface_serializer
        metadata:             ~ # default: broadway.simple_interface_serializer