【问题标题】:Laravel push notifications are received by pusher with sync but not with redis driverLaravel 推送通知由带有同步但不与 redis 驱动程序的推送器接收
【发布时间】:2020-12-22 14:38:28
【问题描述】:

我正在尝试使用 Laravel 的通知类在操作时发送系统通知。我在使用同步驱动时收到通知,但是当我切换到 redis 队列连接时,没有通过推送器的有效负载。

SystemNotification.php

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Channels\BroadcastChannel;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;

class SystemNotification extends Notification implements ShouldQueue
{
    use Queueable;

    private $event;
    private $eventData;

    public function __construct($event, $eventData) {
        $this->event = $event;
        $this->eventData = $eventData;
    }

    /**
     * Get the delivery channels for this Notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable) {
        return [BroadcastChannel::class];
    }

    public function toBroadcast($notifiable) {
        return (new BroadcastMessage([
            'event' => $this->event,
        ]));
    }
}

.env

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

queue.php

'redis' => [
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => env('REDIS_QUEUE', 'default'),
    'retry_after' => 90,
    'block_for' => null,
 ],

这是我使用同步驱动程序时的有效负载。

我的工作也正在成功处理中。

我将不胜感激任何和所有的帮助。谢谢!

【问题讨论】:

  • 你的问题解决了吗?

标签: laravel notifications


【解决方案1】:

要做的事情: 检查您的日志。 检查你的 redis 数据库连接。 确保您的 redis 依赖项已安装。 也许弄清楚这 37 个问题是什么。

试试php artisan config:cache

试试php artisan queue:listen redis

我期待

public function via($notifiable) {
    return [BroadcastChannel::class];
}

成为

public function via($notifiable) {
    return ['broadcast'];
}

除此之外,我找不到您的代码“关闭”的任何内容。

redis 队列的文档可以在这里找到: https://laravel.com/docs/7.x/queues#driver-prerequisites

【讨论】:

    【解决方案2】:

    php artisan queue:listen redis 将在您没有任何错误的情况下为您工作

    【讨论】:

      【解决方案3】:

      配置更改后执行php artisan config:cache 然后重新运行队列工作人员。

      请注意,如果您正在排队使用 redis,那么您必须通过 php artisan queue:listen redis 而不是仅通过 php artisan queue:listen 运行您的工作人员

      如果它不起作用,请尝试实现ShouldBroadcastNow 接口,例如class SystemNotification extends Notification implements ShouldBroadcastNow,然后重新检查它是否真的有效,它不会将您的事件排队,而是立即执行它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-17
        • 2019-04-23
        • 2014-03-31
        • 2016-08-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多