V
V
Vlad Avtomat2018-12-19 17:54:25
Redis
Vlad Avtomat, 2018-12-19 17:54:25

Why does Node+Redis server not see events called by Laravel (5.7)?

Please help, I don't know where to look anymore.. What am I doing wrong?
Here is the node server code:

const port = 6001;
let http = require('http').Server();
let io = require('socket.io')(http);
let Redis = require('ioredis');
let redis = new Redis;

// Подписывает клиента на данные шаблоны

redis.psubscribe('*', function (error, count) {
    console.log('psubscribe');
    console.log(error, count);
});

redis.on('pmessage', function (pattern, channel, message) {
    console.log(channel, message);
});

http.listen(port, function () {
   console.log('Listening on Port: '+ port);
});

Here is the event code that should be picked up by our radish:
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class TestEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return ['micro-time'];
    }

    public function broadcastWith()
    {
        return [
            'time' => microtime(),
            'version' => 0.1
        ];
    }

    public function broadcastAs()
    {
        return 'micro-time';
    }
}

Here are the configs:
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

Redis itself is included.
Events for some reason are processed only through the listener
( php artisan queue:listen)
But the
redis.on('pmessage') server node method
does not respond ....
Who knows what is the reason? help me please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2019-01-13
@Alex_Wells

1) check if the config is cached. Make php artisan config:clear
2) "For some reason, events are processed only through the listener" - because you are using the ShouldBroadcast interface and not ShouldBroadcastNow. In your case, the events first get into the queue, and then it scatters them.

V
Vlad Avtomat, 2018-12-20
@VladSavelev

In general, I did the same thing on laravel 5.2 - everything works fine.
Redis listens to channels.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question