Reputation: 218
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 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,
],
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!
Upvotes: 1
Views: 1681
Reputation: 562
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
Upvotes: 0
Reputation: 36
php artisan queue:listen redis
will work for you assuming you dont have any errors
Upvotes: 0
Reputation: 1206
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.
Upvotes: 3