interactive-solutions / zf-bernard
1.2.4
2017-11-02 18:24 UTC
Requires
- php: ^7.0.0
- bernard/bernard: 1.0.0-alpha6
This package is auto-updated.
Last update: 2024-09-05 03:54:51 UTC
README
提供zend框架2、3和zend-expressive集成
安装
我们支持通过composer安装,注意目前您需要将最小稳定性设置为alpha才能安装
composer require interactive-solutions/zf-bernard
用法
消费队列
$ php public/index interactive-solutions:bernard:consume <queueName>
您还可以传递以下选项
--max-runtime=<VALUE>
:这将使消费者在<VALUE>
秒后关闭。默认为PHP_INT_MAX--stop-on-failure
:这将使消费者在未处理的异常时停止。默认关闭--max-messages=<VALUE>
:这将使消费者在运行<VALUE>
条消息后关闭。默认无限--stop-on-empty
:这将使消费者运行所有队列中的消息然后关闭。默认关闭
标准化器
您可以通过将其添加到BernardOptions::enabledNormalizers
来添加您希望使用的任何标准化器
默认启用的标准化器包括
Bernard\Normalizer\DefaultMessageNormalizer
Bernard\Normalider\EnvelopeNormalizer
InteractiveSolutions\Bernard\Normalizer\ExplicitNormalizer
添加到队列
创建一个扩展AbstractExplicitMessage
类的对象并将其添加到生产者队列,如下所示
final class SomeClass { // This method is called when the task is consumed public function __invoke(Message $message) { // do stuff } } final class Message extends AbstractExplicitMessage { // various parameters for your application /** * Message constructor. */ public function __construct(...parameters) { // Initialize parameters } /** * @return string */ public function getName() { return SomeClass::class; } // getters for your parameters public function getQueue(): string { return 'some-queue'; } } $producer->produce(new Message(...parameters));
在配置中将SomeClass
注册到bernard_consumer_manager
下,完成。
使用代理工厂连接到事件管理器
此代理工厂支持zend框架服务管理器2和3,更多关于它的信息在这里
引入ClearObjectManager事件监听器的示例
final class EventDispatcherDelegateFactory implements DelegatorFactoryInterface { public function __invoke(ContainerInterface $container, $requestedName, callable $callback, array $options = null) { /* @var $dispatcher EventDispatcherInterface */ $dispatcher = $callback(); $dispatcher->addListener(BernardEvents::ACKNOWLEDGE, $container->get(ClearObjectManager::class)); return $dispatcher; } public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback) { return $this($serviceLocator, $requestedName, $callback); } }