PHP code example of tttlkkkl / php_nsq_client

1. Go to this page and download the library: Download tttlkkkl/php_nsq_client 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/ */

    

tttlkkkl / php_nsq_client example snippets


    $lookupHost = '127.0.0.1:4160';
    $topic = $channel = 'test';
    // 重复排队10次,每次50秒延时下发
    $reQueue = new \NsqClient\lib\requeue\Requeue(10, 50);
    $client = new Client(
        $topic,
        $channel,
        '',
        function (\NsqClient\lib\message\Message &$message) {
            echo "收到消息:{$message->getId()}\n";
            $message->finish();
        },
        true,
        null,
        $reQueue,
        [
            'heartbeat_interval' => 1000//1秒的心跳间隔
        ]
    );
    // 开启的工作进程数
    $workNum = 2;
    (new NsqClient())->init($client, $lookupHost, $workNum);giot

composer