PHP code example of camry / nsqclient

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

    

camry / nsqclient example snippets


$topic = 'my_topic';
$endpoint = new \NSQClient\Access\Endpoint('http://127.0.0.1:4161');
$message = new \NSQClient\Message\Message('hello world');
$result = \NSQClient\Queue::publish($endpoint, $topic, $message);

$topic = 'my_topic';
$endpoint = new \NSQClient\Access\Endpoint('http://127.0.0.1:4161');
$message = (new \NSQClient\Message\Message('hello world'))->deferred(5);
$result = \NSQClient\Queue::publish($endpoint, $topic, $message);

$topic = 'my_topic';
$endpoint = new \NSQClient\Access\Endpoint('http://127.0.0.1:4161');
$message = \NSQClient\Message\Bag::generate(['msg data 1', 'msg data 2']);
$result = \NSQClient\Queue::publish($endpoint, $topic, $message);

$topic = 'my_topic';
$channel = 'my_channel';
$endpoint = new \NSQClient\Access\Endpoint('http://127.0.0.1:4161');
\NSQClient\Queue::subscribe($endpoint, $topic, $channel, function (\NSQClient\Contract\Message $message) {
    echo 'GOT ', $message->id(), "\n";
    // make done
    $message->done();
    // make retry immediately
    // $message->retry();
    // make retry delayed in 10 seconds
    // $message->delay(10);
});