Provides zend framework 2, 3 and zend-expressive integrations
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
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
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
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.
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);
}
}