[英]laravel event not send to pusher
我有推送器應用程序,然后我嘗試通過 Laravel 事件向推送器發送消息,這是我的事件:
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewOrder
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $email;
public $message;
public function __construct($email)
{
$this->email = $email;
$this->message = "New order from {$email}, please check.";
//
}
public function broadcastOn()
{
return ['new-order'];
}
}
我嘗試用路由測試來測試它,
Route::get('test', function () {
event(new App\Events\NewOrder('John'));
return "Event has been sent!";
});
我的推送器配置已像推送器的帳戶配置一樣進行配置,但在訪問/test
,推送器調試控制台不顯示任何內容。
'default' => env('BROADCAST_DRIVER', 'pusher'),
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
// 'cluster' => 'ap1',
'encrypted' => true,
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
我不知道從 Laravel 應用程序中看到推送者的日志,有人可以幫助我嗎? 我正在使用 Laravel 5.5
我認為問題在於您的事件類聲明,您應該實現ShouldBroadcastNow
因為它會立即觸發事件並且不需要隊列實現。 默認情況下,您需要設置一個隊列,然后運行該隊列來觸發事件。
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class NewOrder implements ShouldBroadcastNow
{
....do your stuff....
}
並查看這個驚人的播放列表,這肯定會解決您的所有問題
我也遇到了這個問題大約 2 個小時。
你忘了實施廣播,
您可以使用:
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class NewOrder implements ShouldBroadcastNow
或者
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewOrder implements ShouldBroadcast
后者則需要一個隊列驅動程序
快樂編碼:)
替換這個:
class NewOrder
有了這個:
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewOrder implements ShouldBroadcast
那應該工作。 如果我能提供更多幫助,請告訴我。
嗨,我也有這個問題,通過清除緩存來解決它! 這是代碼!
php artisan config:cache
php artisan config:clear
php artisan route:cache
php artisan route:clear
php artisan optimize --force
希望能對你有所幫助!
在這里我如何解決錯誤
Pusher.logToConsole = true;
var key = '<?php echo env('PUSHER_APP_KEY') ?>';
var pusher = new Pusher(key,{
cluster: 'ap2',
forceTLS: true
});
var channel = pusher.subscribe('channel-name');
channel.bind('App\\Events\\EventName',function (data) {
console.log("OK");
console.log(data);
});
'useTLS' => true
選項解決了我的問題。
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
]
檢查 .env 文件QUEUE_CONNECTION=sync
或者你必須運行php artisan queue:work
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.