【问题标题】:Laravel 5.6 Notification Broadcast is queued but not sentLaravel 5.6 通知广播已排队但未发送
【发布时间】:2018-08-14 15:50:51
【问题描述】:

我设置了以下通知

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

这在我的本地机器上运行良好,但是当我将它放到我们的暂存环境中时,它出现了问题。

首先,邮件可以正常发送到日志。数据库也充满了通知。广播正在被队列接收,但它只是像这样坐在那里:

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

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

【问题讨论】:

  • 看起来它处于暂停状态 - 你可以尝试 php artisan horizo​​n:continue
  • 我做了所有适用的地平线命令。请参阅下面的答案:)

标签: laravel pusher


【解决方案1】:

因此,对于我们的暂存环境,我们使用 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,
            ],
        ],    
    ],

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 2018-01-06
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    相关资源
    最近更新 更多