skip to Main Content

I’m trying to use Laravel’s notification class to send a system notification upon an action. I’m receiving notifications when sync driver is being used, but when I switch to redis queue connection, there is no payload through pusher.

SystemNotification.php

<?php

namespace AppNotifications;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsChannelsBroadcastChannel;
use IlluminateNotificationsMessagesBroadcastMessage;
use IlluminateNotificationsNotification;

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

Here is the payload when I use sync driver.

enter image description here

My job is also being successfully processed.

enter image description here

I would appreciate any and all the help. Thanks!

3

Answers


  1. After config change do a php artisan config:cache then re run you queue workers.

    Note if your are queuing to redis then you have to run your workers via php artisan queue:listen redis and not php artisan queue:listen only

    If it does not work try implementing a ShouldBroadcastNow interface like class SystemNotification extends Notification implements ShouldBroadcastNow and then recheck if its works actually it will not queue you event but execute it immediately.

    Login or Signup to reply.
  2. php artisan queue:listen redis will work for you assuming you dont have any errors

    Login or Signup to reply.
  3. Things to do:
    Check your logs.
    Check your redis database connection.
    Make sure your redis dependencies are installed.
    Maybe figure out what those 37 problems are.

    Try php artisan config:cache

    Try php artisan queue:listen redis

    I expected

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

    to be

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

    Other than this I couldn’t find anything "off" with your code.

    The documentation for redis queues can be found here:
    https://laravel.com/docs/7.x/queues#driver-prerequisites

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search