2017-09-27 33 views
0

私はプロジェクトでLaravelを使用していますので、laravel-echo-serverとRedisでブロードキャストを使用したいと思います。私はドッカーのコンテナに両方を設置しました。以下の出力:ブロードキャスト、laravel-echo-serverがイベントを受信して​​いません

Redis

redis_1    | 1:C 27 Sep 06:24:35.521 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 
    redis_1    | 1:C 27 Sep 06:24:35.577 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=1, just started 
    redis_1    | 1:C 27 Sep 06:24:35.577 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 
    redis_1    | 1:M 27 Sep 06:24:35.635 * Running mode=standalone, port=6379. 
    redis_1    | 1:M 27 Sep 06:24:35.635 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 
    redis_1    | 1:M 27 Sep 06:24:35.635 # Server initialized 
    redis_1    | 1:M 27 Sep 06:24:35.635 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 
    redis_1    | 1:M 27 Sep 06:24:35.636 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 
    redis_1    | 1:M 27 Sep 06:24:35.715 * DB loaded from disk: 0.079 seconds 
    redis_1    | 1:M 27 Sep 06:24:35.715 * Ready to accept connections 

いくつかの警告が、何も破壊。

laravel-echo-server

laravel-echo-server_1 | L A R A V E L E C H O S E R V E R 
laravel-echo-server_1 | 
laravel-echo-server_1 | version 1.3.1 
laravel-echo-server_1 | 
laravel-echo-server_1 | ⚠ Starting server in DEV mode... 
laravel-echo-server_1 | 
laravel-echo-server_1 | ✔ Running at localhost on port 6001 
laravel-echo-server_1 | ✔ Channels are ready. 
laravel-echo-server_1 | ✔ Listening for http events... 
laravel-echo-server_1 | ✔ Listening for redis events... 
laravel-echo-server_1 | 
laravel-echo-server_1 | Server ready! 
laravel-echo-server_1 | 
laravel-echo-server_1 | [6:29:38 AM] - dG0sLqG9Aa9oVVePAAAA joined channel: office-dashboard 

クライアントは何の問題もなくチャンネルに参加しているようです。 しかし、私がイベントを蹴った場合、laravel-echo-serverはイベントを受信しません。

私は少しの研究を行い、キューワーカーについて何かを発見しました。だから私はそれを実行することに決めた(php artisan queue:work)、それが何かをしたかどうかを確認します。ドキュメントによれば、キュー内の最初のタスクのみを実行して終了する必要があります(queue:listenとは対照的に)。そして、私が以前に蹴ったイベントを処理し始めたと確信しています。私はそれを殺したまでしかし、それは停止し、行く保たれませんでした:

[2017-09-27 08:33:51] Processing: App\Events\CompanyUpdated 
[2017-09-27 08:33:51] Processing: App\Events\CompanyUpdated 
[2017-09-27 08:33:51] Processing: App\Events\CompanyUpdated 
[2017-09-27 08:33:51] Processing: App\Events\CompanyUpdated 
etc.. 

次の出力は、Redisのコンテナに示した:

redis_1    | 1:M 27 Sep 06:39:01.562 * 10000 changes in 60 
seconds. Saving... 
redis_1    | 1:M 27 Sep 06:39:01.562 * Background saving started by pid 19 
redis_1    | 19:C 27 Sep 06:39:01.662 * DB saved on disk 
redis_1    | 19:C 27 Sep 06:39:01.663 * RDB: 2 MB of memory used by copy-on-write 
redis_1    | 1:M 27 Sep 06:39:01.762 * Background saving terminated with success 

は今、私はどちらかでしたので、多くのAPIは、キューがそうであることを呼び出します大規模な、または何かが間違っている。さらに、laravel-echo-serverは、ジョブが「処理された」後に出力を表示しませんでした。

私がイベントのキック私のモデルでフックを作成しました:

public function __construct(array $attributes = []) { 
    parent::__construct($attributes); 

    parent::created(function($model){ 
     //event(new CompanyCreated($model)); 
    }); 

    parent::updated(function($model){ 
     event(new CompanyUpdated($model)); 
    }); 

    parent::deleted(function($model){ 
     event(new CompanyDeleted($model)); 
    }); 
} 

そして、これはそれがキックオフイベントです:

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

/** 
* Create a new event instance. 
* 
* @return void 
*/ 
public function __construct(Company $company) { 
    $this->company = $company; 
} 

/** 
* Get the channels the event should broadcast on. 
* 
* @return Channel|array 
*/ 
public function broadcastOn() { 
    return new Channel('office-dashboard'); 
} 
} 

そして最後に、これは上のコードでありますイベントを受け取るのフロントエンド:

window.Echo.channel('office-dashboard') 
    .listen('CompanyUpdated', (e) => { 
    console.log(e.company.name); 
    }); 

.envファイル:

BROADCAST_DRIVER=redis 
CACHE_DRIVER=file 
SESSION_DRIVER=file 
QUEUE_DRIVER=redis 

REDIS_HOST=redis 
REDIS_PASSWORD=null 
REDIS_PORT=6379 

laravel-echo-serverにイベントが渡されないのはなぜですか?私は行方不明または忘れているものは何ですか?

+0

.envでブロードキャストドライバを変更しましたか? –

+0

はい、私は自分の.envからコードの関連するビットを表示するために私の質問を更新しました – Snackoverflow

+0

キューしましたか?それは失敗しているようです。多分キューを処理していない場合にエラーを見るためにキュードライバを変更しようとする可能性があります –

答えて

関連する問題