Laravel 5.6 通知广播已排队但未发送

Laravel 5.6 Notification Broadcast is queued but not sent

我设置了以下通知

BillProcessed.php

<?php

namespace App\Notifications;

use App\Bill;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\BroadcastMessage;

class BillProcessed extends Notification
{
    use Queueable;

    protected $bill;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Bill $bill)
    {
        $this->bill = $bill;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        // Only send mail if this feature is turned on
        return config('features.bill_processed_mail', false) ? ['mail', 'broadcast', 'database'] : ['broadcast', 'database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->greeting("Hello {$notifiable->name},")
            ->line('A new Bill has been processed!')
            ->action('View Bill', url('/bills/' . $this->bill->id))
            ->line('Thank you for using our application!');
    }

    /**
     * Get the database representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toDatabase($notifiable)
    {
        return [
            'message' => 'New Bill Processed',
            'bill' => $this->getBillStub(),
        ];
    }

    /**
     * Get the database representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'data' => [
                'message' => 'New Bill Processed',
                'bill' => $this->getBillStub(),
            ],
        ]);
    }

    protected function getBillStub()
    {
        return [
            'id' => $this->bill->id,
            'due_date' => $this->bill->due_date->format('m-d-Y'),
            'site_code' => $this->bill->account->site->code,
            'site_name' => $this->bill->account->site->name,
            'type' => $this->bill->account->types->first()->name,
            'created' => $this->bill->created_at->format('m-d-y H:i:s'),
        ];
    }
}

这在我的本地机器上工作得很好,但是当我把它放在我们的暂存环境中时它有问题。

首先,邮件进入日志就好了。数据库也被通知填满了。队列正在接收广播,但它只是像这样坐在那里:

它没有失败或超时,它只是处于这种状态。我已经尝试重新启动 Supervisor,但仍然一无所获。

我还四重检查了我的 env 文件中是否有正确的 PUSHER 信息。

因此,对于我们的暂存环境,我们使用 APP_ENV=uat。如果您不使用 "production" 或 "local" 作为您的 APP_ENV,您需要发布 horizon 配置并将您的环境添加到其中,如下所示:

   'environments' => [
        'production' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'auto',
                'processes' => 10,
                'tries' => 3,
            ],
        ],
        'local' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'auto',
                'processes' => 3,
                'tries' => 3,
            ],
        ],
        'uat' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'auto',
                'processes' => 3,
                'tries' => 3,
            ],
        ],    
    ],

否则horizon将不知道该听哪个队列而无所事事。希望这对您有所帮助!