@fortionfortune/noderavel

0.0.2 • Public • Published

Noderavel

Queue sync between NodeJS and Laravel using Redis driver. You can process Jobs dispatched from Laravel in NodeJS or biceversa.

Install

npm install @movilizame/noderavel --save

Usage

  • Listen for jobs on NodeJS:
const Noderavel = require('@movilizame/noderavel');
const redis = require('redis');

redisCliente = redis.createClient(6379, 'localhost'); 

class TestJob {
    constructor(a, b) {
        this.a = a;
        this.b = b;
    }
}

let queueWorker = new Noderavel({
    client: redisCliente,
    driver: 'redis',
    scope: {
        'App\\Jobs\\TestJob': TestJob
    }
});

queueWorker.on('job', ({name, data}) => {
    console.log(name, data);
    // Proccess your jobs here.
});

queueWorker.listen();
  • Schedule a job to be run in Laravel from NodeJS:
const Noderavel = require ('@movilizame/noderavel');
const redis = require('redis');

const redisHost = 'localhost';
const redisPort = 6379;
redisCliente = redis.createClient(redisPort, redisHost); 

class TestJob {
    constructor(a, b) {
        this.a = a;
        this.b = b;
    }
}

let queueWorker = new Noderavel({
    client: redisCliente,
    driver: 'redis',
    scope: {
        'App\\Jobs\\TestJob': TestJob
    }
}); 

for (let i = 0; i < 10; i++) {
    let job = new TestJob('param1', i);
    queueWorker.redisPush('App\\Jobs\\TestJob', job);
}

TestJob in Laravel:

<?php

namespace App\Jobs; 
use Illuminate\Contracts\Queue\ShouldQueue;

class TestJob extends Job implements ShouldQueue
{
    public $a, $b;
    public function __construct ($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    function handle () {
        \Log::info('TestJob ' . $this->a . ' '. $this->b);
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @fortionfortune/noderavel

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

9.72 kB

Total Files

7

Last publish

Collaborators

  • fortionfortune