laravel-echo-server 不广播事件

laravel-echo-server not broadcasting events

我按照配置 laravel-echo-server 的文档将 redis 作为广播驱动程序。

我成功加入了我创建的频道,但在命令的输出中 DEBUG=* laravel-echo-server start 我得到了这个:

Server ready!

  engine intercepting request for path "/socket.io/" +0ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MapZmuQ" +1ms
  engine handshaking client "qu2wNp4IrLre3oJeAAAA" +7ms
  engine:socket sending packet "open" ({"sid":"qu2wNp4IrLre3oJeAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}) +0ms
  engine:socket sending packet "message" (0) +1ms
  engine:polling setting request +0ms
  engine:socket flushing buffer to transport +1ms
  engine:polling writing "96:0{"sid":"qu2wNp4IrLre3oJeAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40" +2ms
  engine:socket executing batch send callback +9ms
  socket.io:server incoming connection with id qu2wNp4IrLre3oJeAAAA +492ms
  socket.io:client connecting to namespace / +0ms
  socket.io:namespace adding socket to nsp / +0ms
  socket.io:socket socket connected - writing packet +0ms
  socket.io:socket joining room qu2wNp4IrLre3oJeAAAA +0ms
  socket.io:socket packet already sent in initial handshake +0ms
  socket.io:socket joined room qu2wNp4IrLre3oJeAAAA +1ms
  engine intercepting request for path "/socket.io/" +206ms
  engine handling "POST" http request "/socket.io/?EIO=3&transport=polling&t=MapZm-U&sid=qu2wNp4IrLre3oJeAAAA" +1ms
  engine setting new request for existing client +0ms
  engine:polling received "121:42["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]" +193ms
  engine:socket packet +186ms
  socket.io-parser decoded 2["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] as {"type":2,"nsp":"/","data":["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]} +690ms
  socket.io:socket got packet {"type":2,"nsp":"/","data":["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]} +183ms
  socket.io:socket emitting event ["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] +0ms
  socket.io:socket dispatching an event ["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] +0ms
  socket.io:socket joining room issueUpdates +1ms
[10:03:27] - qu2wNp4IrLre3oJeAAAA joined channel: issueUpdates
  socket.io:socket joined room issueUpdates +6ms
  engine intercepting request for path "/socket.io/" +83ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MapZm-U.0&sid=qu2wNp4IrLre3oJeAAAA" +0ms
  engine setting new request for existing client +1ms
  engine:polling setting request +83ms
  engine upgrading existing transport +67ms
  engine:socket might upgrade socket transport from "polling" to "websocket" +149ms
  engine:ws received "2probe" +0ms
  engine:ws writing "3probe" +1ms
  engine:socket writing a noop packet to polling for fast upgrade +170ms
  engine:polling writing "1:6" +238ms
  engine:ws received "5" +185ms
  engine:socket got upgrade packet - upgrading +83ms
  engine:polling closing +84ms
  engine:polling transport discarded - closing right away +0ms
  engine:ws received "2" +25s
  engine:socket packet +25s
  engine:socket got ping +0ms
  engine:socket sending packet "pong" (undefined) +0ms
  engine:socket flushing buffer to transport +0ms
  engine:ws writing "3" +1ms

我可以看到它接收 ping 并发送 pong,但我不知道为什么我的 event(new IssueCreated($issue)) 永远不要扔掉频道并被广播。

我的前端代码:

if (io !== 'undefined') {
    console.log('subscribing..');
    // Issue created code
    Echo.channel('issueUpdates')
        .listen('IssueCreated', (e) => {
            console.log('new issue');
            console.log(e);
        });
}

我知道我已成功加入房间,但是当我触发事件时,它既没有显示在我的 laravel-echo-server 日志中,也没有显示在我的 console.log[=15 中=]

我可以做些什么来调试?如果您需要更多信息,请告诉我。

好的,遇到同样问题的人:

我的问题出在队列侦听器的配置上,我使用主管来保持进程处于活动状态,并且我没有使用 php artisan queue:listen

正确配置命令属性

切记,您必须同时拥有 2 个东西 运行,laravel-echo-server startphp artisan queue:listen

如果您只是 运行 laravel-echo-server 并且想知道为什么您的事件没有触发,请按照 this link 配置 laravel 队列。