Laravel package for NSQ. This package NOT use laravel's api.
First, require the package using Composer:
composer require androzd/queue-nsq
You can configure with env variables.
If you need more options to replace, you can publish and edit config file:
php artisan vendor:publish --provider="Androzd\QueueNsq\QueuesServiceProvider" --tag="config"
<?php
use Androzd\QueueNsq\Actions\ProduceMessageToTopic;
$message = json_encode(['id' => 'example message']);
$topic = 'example-topic';
$produceAction = new ProduceMessageToTopic();
$produceAction($message, $topic);
<?php
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
<?php
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
}
}