Fully unit-tested Laravel ZeroMQ driver based on react/zmq.
Install package:
composer require denpa/laravel-zeromq "^1.0"
(skip if using Laravel 5.5 or newer) Add service provider and facade to ./config/app.php
'providers' => [
...
Denpa\ZeroMQ\Providers\ServiceProvider::class,
];
'aliases' => [
...
'ZeroMQ' => Denpa\ZeroMQ\Facades\ZeroMQ::class,
];
php artisan vendor:publish --provider="Denpa\ZeroMQ\Providers\ServiceProvider"
in your project directory.Publish:
zeromq()->publish(['foo', 'bar'], 'hello');
zeromq()->connection('test')->publish(['foo', 'bar'], 'hello');
Pull:
zeromq()->pull(function ($message) {
echo $message;
});
Push:
zeromq()->push('hello');
Subscribe:
zeromq()->subscribe(['foo', 'bar'], function ($message) {
echo $message;
});
use Denpa\ZeroMQ\Facades\ZeroMQ;
$callback = function ($message) {
echo $message;
};
// use default connection
ZeroMQ::publish(['foo', 'bar'], 'hello');
ZeroMQ::pull($callback);
ZeroMQ::push('hello');
ZeroMQ::subscribe(['foo', 'bar'], $callback);
// use different connection
ZeroMQ::connection('baz')->push('hello');
Set BROADCAST_DRIVER=zeromq
in environment file and add following lines
'zeromq' => [
'driver' => 'zeromq',
],
to 'connections' key in config/broadcasting.php
.
Now use laravel broadcast($event);
helper to broadcast events via ZeroMQ.
laravel-bitcoinrpc integrates this package to subscribe to topics broadcasted by Bitcoin Core (and some forks).
bitcoind()->on('hashblock', function ($blockhash, $sequence) {
// get hash of new best block and retrieve full block info
$block = bitcoind()->getBlock($blockhash);
print_r($block->get());
});
For more info, visit laravel-bitcoinrpc documentation.
This product is distributed under MIT license.