Exemplo n.º 1
0
 public function testUnsubscribeAllCallbacksForEvent()
 {
     $objMock = $this->getMock('stdClass', array('assert'));
     $objMock->expects($this->never())->method('assert');
     $event = new Event(uniqid());
     // attach multiple different callbacks to event
     for ($i = rand(1, 4); $i > 0; $i--) {
         $this->pubSub->subscribe($event, function () use($objMock) {
             $objMock->assert();
         });
     }
     $this->pubSub->unsubscribe($event);
     $msg = new AMQPMessage($event->toJson());
     $this->pubSub->onMessage($msg);
 }
Exemplo n.º 2
0
<?php

use SoPhp\PubSub\PubSub;
require_once 'bootstrap.php';
$pubSub = new PubSub($ch, EXCHANGE);
$pubSub->publish('hello', array('who' => @$argv[1] ?: 'world'));
Exemplo n.º 3
0
<?php

use SoPhp\PubSub\Event;
use SoPhp\PubSub\PubSub;
require_once 'bootstrap.php';
$pubSub = new PubSub($ch, EXCHANGE);
$pubSub->subscribe('hello', function (Event $e) {
    echo "Hello " . $e->getParam('who', 'guest') . PHP_EOL;
});
while (count($ch->callbacks)) {
    $ch->wait();
}