2017 © Pedro Peláez
 

library redis-broker

PHP Redis message broker

image

yoye/redis-broker

PHP Redis message broker

  • Monday, December 4, 2017
  • by yoye
  • Repository
  • 3 Watchers
  • 4 Stars
  • 39,932 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 13 Versions
  • 2 % Grown

The README.md

redis-broker

PHP Redis message broker, (*1)

Installation

The recommended way to install redis-broker is through Composer, (*2)

composer require "yoye/redis-broker" "dev-master"

Usage

<?php

// broker.php

require_once __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\EventDispatcher\EventDispatcher;
use Yoye\Broker\Adapter\PhpRedisAdapter;
use Yoye\Broker\Broker;
use Yoye\Broker\Event\BrokerEvents;
use Yoye\Broker\Event\MessageEvent;

$client = new Redis();
$client->connect('127.0.0.1', 6379, 0);
$adapter = new PhpRedisAdapter($client);
$dispatcher = new EventDispatcher();
$dispatcher->addListener(BrokerEvents::MESSAGE_RECEIVED, function(MessageEvent $event) {
        $channel = $event->getChannel();
        $message = $event->getMessage();

        var_dump($channel, $message);

        // The event must be marked has done 
        // otherwise the listener will be called indefinitely
        $event->setDone();
});

$broker = new Broker($adapter, ['foo.channel', 'bar.channel'], $dispatcher);
$broker->run();

Now type in your console, (*3)

php broker.php

On another console type redis-cli LPUSH foo.channel 'This is a message' or redis-cli LPUSH bar.channel 'This is a message', on your first console you should see:, (*4)

string(11) "foo.channel"
string(17) "This is a message"

You can also set a repetition limit's, if this limit is reached, a new event will be launched., (*5)

$client = new Redis();
$client->connect('127.0.0.1', 6379, 0);
$adapter = new PhpRedisAdapter($client);
$dispatcher = new EventDispatcher();
$dispatcher->addListener(BrokerEvents::MESSAGE_RECEIVED, function(MessageEvent $event) {
    var_dump($event->getMessage());
    if ($event->getMessage() === 'FooBar') {
        $event->setDone();
    }
});
$dispatcher->addListener(BrokerEvents::NESTING_LIMIT, function(MessageEvent $event) {
    var_dump('Last call for: ' . $event->getMessage());
});

$broker = new Broker($adapter, ['foo.channel', 'bar.channel'], $dispatcher);
$broker->setNestingLimit(3);
$broker->run();

Now if you type LPUSH foo.channel 'This is a message' 'FooBar', you should see:, (*6)

string(17) "This is a message"
string(6) "FooBar"
string(17) "This is a message"
string(17) "This is a message"
string(32) "Last call for: This is a message"

The Versions

04/12 2017

dev-master

9999999-dev

PHP Redis message broker

  Sources   Download

MIT

The Requires

 

The Development Requires

04/12 2017
25/08 2016
18/05 2016
23/03 2016
07/04 2015
03/04 2015
26/02 2015
26/02 2015
05/11 2014
08/08 2014

v2.0

2.0.0.0

Redis messsage broker writing in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/01 2014

v1.1

1.1.0.0

Redis messsage broker writing in PHP

  Sources   Download

MIT

The Requires

 

10/01 2014

v1.0

1.0.0.0

Redis messsage broker writing in PHP

  Sources   Download

MIT

The Requires