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.
My job is also being successfully processed.
I would appreciate any and all the help. Thanks!
3
Answers
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 notphp artisan queue:listen
onlyIf it does not work try implementing a
ShouldBroadcastNow
interface likeclass SystemNotification extends Notification implements ShouldBroadcastNow
and then recheck if its works actually it will not queue you event but execute it immediately.php artisan queue:listen redis
will work for you assuming you dont have any errorsThings 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
to be
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