Answer the question
In order to leave comments, you need to log in
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);
});
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';
}
}
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
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question