interactive-solutions / zf-bernard
Installs: 3 532
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^7.0.0
- bernard/bernard: 1.0.0-alpha6
This package is auto-updated.
Last update: 2024-11-05 04:13:17 UTC
README
Provides zend framework 2, 3 and zend-expressive integrations
Installing
We support installation via composer, note for now you need to set the minimum stability to alpha to install
composer require interactive-solutions/zf-bernard
Usage
To consume a queue:
$ php public/index interactive-solutions:bernard:consume <queueName>
You can also pass the following options:
--max-runtime=<VALUE>
: This will make the consumer shutdown after<VALUE>
seconds. PHP_INT_MAX by default--stop-on-failure
: This will make the consumer halt on unhandled exceptions. Off by default--max-messages=<VALUE>
: This will make the consumer shutdown after<VALUE>
messages are ran. Infinite by default--stop-on-empty
: This will make the consumer run all the queued messages and then shutdown. Off by default
Normalizers
You can add any normalizer that you wish to use by adding it to the BernardOptions::enabledNormalizers
The default enabled normalizers are
Bernard\Normalizer\DefaultMessageNormalizer
Bernard\Normalider\EnvelopeNormalizer
InteractiveSolutions\Bernard\Normalizer\ExplicitNormalizer
Add to the queue
Create an object extending the AbstractExplicitMessage
class and
it to the producer queue like this:
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));
Register the SomeClass
under bernard_consumer_manager
in the config
and you're done.
Hooking into the event manager using a delegate factory
This delegate factory supports both zend framework service manager 2 & 3, read more about it here
Example of introducing the ClearObjectManager event listener
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); } }