androzd/queue-nsq

There is no license information available for the latest version (v1.0.7) of this package.

NSQ package for laravel

v1.0.7 2024-04-08 09:00 UTC

This package is auto-updated.

Last update: 2024-11-10 10:33:25 UTC


README

Laravel package for NSQ. This package NOT use laravel's api.

Installation

First, require the package using Composer:

composer require androzd/queue-nsq

Configuration

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"

Produce new Nsq message:

<?php

use Androzd\QueueNsq\Actions\ProduceMessageToTopic;

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

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

Produce new deferred Nsq message:

<?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

Listen Nsq topic:

<?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
    }
}