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

时间:2018-08-14 15:50:52

标签: laravel pusher

我设置了以下通知

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'),
        ];
    }
}

这在我的本地计算机上工作得很好,但是当我将其放在暂存环境中时,就会遇到问题。

首先,邮件即将进入日志。数据库中也充满了通知。广播正在排队等候,但它只是像这样坐在那里:

enter image description here

这不是失败或超时,它只是处于这种状态。我尝试重新启动Supervisor,但仍然没有任何反应。

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

1 个答案:

答案 0 :(得分:0)

因此,对于我们的暂存环境,我们使用APP_ENV = uat。如果您未将“生产”或“本地”用作APP_ENV,则需要发布Horizo​​n配置并向其中添加环境:

   '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,
            ],
        ],    
    ],

否则,地平线将不知道该听哪个队列,并且会无所事事。希望这会有所帮助!

相关问题