1. Go to this page and download the library: Download per3evere/nsqphp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
per3evere / nsqphp example snippets
// 原生的方式
$nsq = new Per3evere\Nsq\nsqphp;
$nsq->publishTo('localhost')
->publish('mytopic', new Per3evere\Nsq\Message\Message('some message payload'));
// Laravel 方式
app('nsq')->publish('mytopic', new Per3evere\Nsq\Message\Message('some message payload'));
$nsq = new Per3evere\Nsq\nsqphp;
$nsq->publishTo(array('nsq1', 'nsq2', 'nsq3'), Per3evere\Nsq\nsqphp::PUB_QUORUM)
->publish('mytopic', new Per3evere\Nsq\Message\Message('some message payload'));
$lookup = new Per3evere\Nsq\Lookup\Nsqlookupd;
$lookup = new Per3evere\Nsq\Lookup\Nsqlookupd('nsq1,nsq2');
$lookup = new Per3evere\Nsq\Lookup\Nsqlookupd;
$nsq = new Per3evere\Nsq\nsqphp($lookup);
$nsq->subscribe('mytopic', 'somechannel', function($msg) {
echo $msg->getId() . "\n";
})->run();
$lookup = new Per3evere\Nsq\Lookup\Nsqlookupd;
$nsq = new Per3evere\Nsq\nsqphp($lookup);
$nsq->subscribe('mytopic', 'somechannel', 'msgCallback')
->run();
function msgCallback($msg)
{
echo $msg->getId() . "\n";
}
$lookup = new Per3evere\Nsq\Lookup\Nsqlookup;
$nsq = new Per3evere\Nsq\nsqphp($lookup);
$nsq->subscribe('mytopic', 'somechannel', 'msgCallback')
->subscribe('othertopic', 'somechannel', 'msgCallback')
->run();