This is a facade for messaging systems.

Installs: 5 427

Dependents: 2

Stars: 2

Watchers: 1

Forks: 1

Language: PHP

1.1.2 2013-09-11 21:33 UTC


This is a messaging facade library. It wraps and hides messaging (event) tools thus you can whenever switch to another one.


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.



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.

/* @var $transactionManager ObservableTransactionManager */
$dispatcher = new TransactedMemoryMessageDispatcher($transactionManager);

/* @var $listener MessageListener */
$dispatcher->addEventListener($queue, $listener);

try {
    // do anything, modify database, etc.
    $dispatcher->send($queue, $message);
    // $message will be delivered to $listener after commit
} catch (Exception $e) {
    // $message won't be delivered


$dispatcher = new MemoryMessageDispatcher();
$queue = new DefaultQueue('queue');

/* @var $listener MessageListener */
$dispatcher->addEventListener($queue, $listener);

Send events

/* @var $object Serializable */
$message = new ObjectMessage($object);
$dispatcher->send($queue, $message);
// onMessage method in $listener is called