ag/event

一个旨在最好地支持TYPO3 Flow PHP框架和领域事件的包,如Vaughn Vernon在《实现领域驱动设计》中所描述的。

安装次数: 1,130

依赖者: 2

建议者: 0

安全性: 0

星标: 11

关注者: 6

分支: 5

开放问题: 5

类型:typo3-flow-package

1.0.0 2015-02-03 10:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:20:11 UTC


README

支持领域事件,这些事件在《领域事件》章节中有描述:[链接](https://vaughnvernon.co/?page_id=168)

为什么?

因为使用领域事件在聚合、模块和边界上下文中传递信息可以减少耦合,并有助于避免贫血的领域模型。

如何?

请参阅Ag.Shop以了解如何集成的示例。

事件处理

有一个CLI命令可以通过./flow event:process {eventHandlerName}执行,其中{eventHandlerName}Settings.yaml中定义,例如这样

Ag:
  Event:
    eventHandlers:
      async:
        'Acme\Foo\EventHandler\SomeThingTriggeredEventHandler': TRUE

按照惯例,类名的命名空间分隔符被替换为下划线,因此在这种情况下键名将是Acme_Foo_EventHandler_SomeThingTriggeredEventHandler

守护进程配置

由于它固有的超时时间,所以必须手动保持提到的CLI命令的活跃状态,以避免例如MySQL连接超时。

为了实现这一点,我们在这里提供三个建议。

使用supervisord

有一个包含以下配置的池

[program:some_thing]
command=/var/www/production/flow event:process Acme_Foo_EventHandler_SomeThingTriggeredEventHandler
environment=FLOW_CONTEXT="Production"
redirect_stderr=true
stdout_logfile=/var/www/production/Data/Logs/Supervisord.log
stderr_logfile=/var/www/production/Data/Logs/Supervisord_error.log
user=theuser
autostart=true
autorestart=true
stopsignal=QUIT
使用守护进程

启动进程的命令类似于以下内容

daemon --name="some_thing" --env="FLOW_CONTEXT=Production" --respawn --stdout="/var/www/production/Data/Logs/DaemonStdOut.log" --stderr="/var/www/production/Data/Logs/DaemonStdErr.log" /var/www/production/flow event:process Acme_Foo_EventHandler_SomeThingTriggeredEventHandler

一旦启动,您可以使用daemon --stop --name="some_thing"停止此守护进程。

使用upstart

有一个upstart配置,特别是respawn处于活动状态。