User101
User101

Reputation: 55

Event broadcast is not working when queueis use in our project

I was broadcasting my event with help of pusher,it's worked fine but when i used queue implementation then pusher haven't receive any broadcast or may be event is not broadcasting.I'm not understand what the issue is.Code is given below please help me

Controller function

public function index()
{       $this->user_id=2;
        Event::fire(new UpdateDeviceStatus($this->user_id));
}

Event file

class UpdateDeviceStatus extends Event implements ShouldBroadcast
{
    use SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public $devices;
    public function __construct($id)
    {
        $this->devices=Device::with('units')->where('user_id',$id)->get();
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['update-status'];
    }
}

js file

Pusher.logToConsole = true;

    var pusher = new Pusher('key', {
        encrypted: true
    });
        var channel = pusher.subscribe('update-status');
        channel.bind('App\\Events\\UpdateDeviceStatus', function (data) {
            console.log(data);

                  });

Upvotes: 0

Views: 533

Answers (1)

Alexcode
Alexcode

Reputation: 1598

I had the same issue and realised that I just forgot to listen to the queue: php artisan queue:listen redis

Upvotes: 1

Related Questions