PHP code example of androzd / queue-nsq

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

    

androzd / queue-nsq example snippets




use Androzd\QueueNsq\Actions\ProduceMessageToTopic;

$message = json_encode(['id' => 'example message']);
$topic = 'example-topic';

$produceAction = new ProduceMessageToTopic();
$produceAction($message, $topic);



use Androzd\QueueNsq\Actions\ProduceDeferredMessageToTopic;

$message = json_encode(['id' => 'example message']);
$topic = 'example-topic';

$produceDeferredAction = new ProduceDeferredMessageToTopic();
$produceDeferredAction($message, $topic, 10_000);//deferred time in ms



use Androzd\QueueNsq\Console\BaseConsumer;

class ExampleTopic extends BaseConsumer
{
    protected $signature = 'queue-work:example_topic';

    public function getTopic(): string
    {
        return 'example-topic';
    }

    public function process(NsqMessage $nsqMessage, $bev)
    {
        $payload = json_decode($nsqMessage->payload);
        // ... your code
    }
}
shell script
php artisan vendor:publish --provider="Androzd\QueueNsq\QueuesServiceProvider" --tag="config"