Alternative for ZeroMQ for "Push to an Existing Site" -example?

115 views
Skip to first unread message

koski....@gmail.com

unread,
Jan 27, 2015, 3:50:04 AM1/27/15
to ratch...@googlegroups.com
Hi guys and gals,

has someone managed to use a alternative broker than ZeroMQ for pushing the messages to PubSub (http://socketo.me/docs/push)?

I am interested of using Redis instead (a list with blocking pull). Has someone tried this already or knows why for example predis-async (https://github.com/nrk/predis-async) would not work?

Cheers,
--
Tuomas

cboden

unread,
Feb 3, 2015, 6:39:00 PM2/3/15
to ratch...@googlegroups.com, koski....@gmail.com
That's very do-able and very similar in execution to the ZMQ tutorial. You'd just hook predis-async into the React EventLoop instead of ZMQ. I plan on writing more/better documentation around this topic in March. 

Tuomas Koski

unread,
Feb 4, 2015, 10:21:43 AM2/4/15
to cboden, ratch...@googlegroups.com
That sounds awesome!

koski....@gmail.com

unread,
Feb 21, 2015, 10:18:03 AM2/21/15
to ratch...@googlegroups.com, koski....@gmail.com
Hi,

cboden wrote:
> You'd just hook predis-async into the React EventLoop instead of ZMQ.

You are right. Now when I understood predis-async and React a bit better, I got this working in no time.

Maybe the parts below helps others too while waiting for the better documentation from cboden.

Important bits from from my main (creating app and loop):

...

$loop   = React\EventLoop\Factory::create();
$pubSubApp = new OpenPubSubRedis($di); // This is my own app, like $pusher in Ratchet tutorials. 

$client = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$client->connect(array($pubSubApp, 'initRedisConnection'));

$webSock = new React\Socket\Server($loop);
$webSock->listen(8183, '0.0.0.0');
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer(
            new Ratchet\Wamp\WampServer(
                $pubSubApp
            )
        )
    ),
    $webSock
);

...

And from my OpenPubSubRedis initialized above class (connecting and handling incoming payloads from redis):

...

public function initRedisConnection(\Predis\Async\Client $redisClient) 
{        
    $this->redisClient = $redisClient;
        
    $channel = 'events-to-ws-pubsub';
    $this->redisClient->pubSubLoop(
        $channel, 
        array(
            $this, 
            'onPublishEventFromRedis'
        )    
    );
}

public function onPublishEventFromRedis($event, $pubsub) 
{
    //var_dump($event);
    
    echo "Kind: $event->kind Channel: $event->channel Payload: $event->payload\n";
    
    // find topic, broadcast and stuff or what ever you want to do.
}

...


Thanks once again cboden! Good stuff with Ratchet!

Cheers,
--
Tuomas
Reply all
Reply to author
Forward
0 new messages