mf4php / mf4php
This is a facade for messaging systems.
Installs: 24 851
Dependents: 2
Suggesters: 1
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- trf4php/trf4php: ~2.0
Requires (Dev)
- phpunit/phpunit: 7.0.2
Suggests
- mf4php/mf4php-beanstalk: If you want to use with Beanstalk
This package is not auto-updated.
Last update: 2024-09-28 12:41:37 UTC
README
This is a messaging facade library. It wraps and hides messaging (event) tools thus you can whenever switch to another one.
Features
There is one implementation shipped with this package, the MemoryMessageDispatcher. It is useful for synchron communications. There is one asynchronous implementation: mf4php/mf4php-beanstalk
Feel free to implement a binding for your preferred event library.
History
1.1
There is a message dispatcher (abstract) implementation: TransactedMessageDispatcher. It can be used with an ObservableTransactionManager coming from trf4php. Sending messages inside a transaction will be delayed until the transaction is committed. The benefit of this feature is that if a message sending causes error then transaction will be rolled back (buffered messages will be deleted). If the commit is successful, then buffered messages will be delivered and inserted/updated records can be reached in message handlers even if the messages were sent before the commit.
<?php /* @var $transactionManager ObservableTransactionManager */ $dispatcher = new TransactedMemoryMessageDispatcher($transactionManager); /* @var $listener MessageListener */ $dispatcher->addEventListener($queue, $listener); $transactionManager->beginTransaction(); try { // do anything, modify database, etc. $dispatcher->send($queue, $message); $transactionManager->commit(); // $message will be delivered to $listener after commit } catch (Exception $e) { $transactionManager->rollback(); // $message won't be delivered }
Configuration
<?php $dispatcher = new MemoryMessageDispatcher(); $queue = new DefaultQueue('queue'); /* @var $listener MessageListener */ $dispatcher->addEventListener($queue, $listener);
Send events
<?php /* @var $object Serializable */ $message = new ObjectMessage($object); $dispatcher->send($queue, $message); // onMessage method in $listener is called