Laravel 5.8通知队列仅发送一个通知

时间:2019-04-07 05:59:24

标签: php notifications priority-queue laravel-5.8

我正在开发应用程序。其中,管理员向用户发送通知。 我使用了laravel 5.8队列通知。生成通知后,作业表有很多行,但是当我运行

php artisan queue:listen --queue=high,medium,default 它只发送一个通知。

我的配置如下:

  1. .env:QUEUE_CONNECTION =数据库
  2. config / queue.php:
'database' => [
           'driver' => 'database',
           'table' => 'jobs',
           'queue' => ['default','medium','high'],
           'retry_after' => 90,
],
  1. NotificationGeneratingController:
$data = new \stdClass();
$data->message =  [
    'data' => $request->notification_text
];
$data->via = 'mail';//$request->notification_via;
$receiver = User::all();
Notification::send($receiver,new UserNotificationQueue($data));
  1. Notifications / UserNotificationQueue.php
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Notifications\Messages\MailMessage;

class UserNotificationQueue extends Notification implements ShouldQueue
{
    use Queueable,SerializesModels;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
     protected $message;
     protected $notification_via;

    public function __construct($data)
    {
        $this->message = $data->message;
        $this->notification_via = $data->via;
        $this->onQueue($data->queue ?? 'medium');
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        $via = $this->notification_via; // default mail
        return [$via];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                ->subject("Notification From: GoGram")
                ->greeting('Hello '.$notifiable->name)
                ->line($this->message['data'])
                ->line('Thank you for using our application!');
    }
}

始终仅发送一个通知。如果作业表混合了队列,则它仅发送优先级更高的通知。我也尝试过config / queue.php

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default'
            'retry_after' => 90,
        ],

         'medium' => [
             'driver' => 'database',
             'table' => 'jobs',
             'queue' => 'medium',
             'retry_after' => 30,
         ],

         'high' => [
             'driver' => 'database',
             'table' => 'jobs',
             'queue' => 'high',
             'retry_after' => 10,
         ],

有什么问题吗?

0 个答案:

没有答案