andy-thorne/domain-events-bundle

Doctrine ODM 和 ORM 的领域事件

安装: 532

依赖者: 0

建议者: 1

安全性: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

2.0.0 2022-01-11 12:46 UTC

This package is auto-updated.

Last update: 2024-09-11 18:12:37 UTC


README

此扩展包通过MessageBus在 doctrine 事件上添加领域事件分派。

CI

安装

composer require andy-thorne/domain-events-bundle

配置

# Defaults
domain_events:
    orm: true
    odm: false
    bus: domain_event.bus
    transport: async_domain_events
    configure_routing: true  # Auto-configures messenger routing for DomainEventInterfaces to route to the configured transport

framework:
    messenger:
        transports:
            async_domain_events: "%env(ASYNC_MESSENGER_TRANSPORT_DSN)%"

该扩展包还会根据您的 domain_events 配置来配置这些 messenger 设置。如果您已经配置了总线,您将需要指定 framework.messenger.default_bus

# The bundle also configures your
framework:
    messenger:
        # Set up a bus that will allows no handlers
        buses:
            <domain_events.bus>:
                default_middleware: allow_no_handlers

        # Route all domain events to the domain event transport if configure_routing is true (default)
        routing:
            'AndyThorne\Components\DomainEventsBundle\Events\DomainEventInterface': <domain_events.transport>

消息总线

领域事件使用应用的 MessageBus 来传输领域事件。默认的 Messenger 组件配置为同步,并为每个消息至少定义一个处理器。为了让领域事件正常工作,我们需要配置异步 MessageBus 并允许它没有处理器

为什么异步?

领域事件在 doctrine postFlush 生命周期事件中分派