jeudi 26 juillet 2018

Laravel - Broacasting with pusher

I just started using pusher because I had problems with redis and socket.io. For that I followed the documentation of Laravel, I created an account on pusher and insert the keys in the file .env.

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=XXXXX
PUSHER_APP_KEY=XXXXXXXXXXXXX
PUSHER_APP_SECRET=XXXXXXXXXXXXXX
PUSHER_APP_CLUSTER=eu

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Then I created an event that implements the should broadcast interface

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class IncrementAddingOrderCounter implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $length;
    public $value;

    /**
     * Create a new event instance.
     *
     * @param $length
     * @param $value
     */
    public function __construct($length, $value)
    {
        $this->length = $length;
        $this->value = $value;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('add.order');
    }

    public function broadcastAs()
    {
        return 'increment.order';
    }
}

Afterwards I emit the event with

event(new IncrementAddingOrderCounter(count($parsedData), $size));

But the execution of the event failed

queue error and if I look in my logs I see this error

[2018-07-26 04:21:26] local.ERROR: Invalid signature: you should have sent HmacSHA256Hex("POST\n/apps/567300/events\nauth_key=ed4ae6670d7eff5270f2&auth_timestamp=1532578885&auth_version=1.0&body_md5=f46404ebd0c36f7d62d1b51ebb85fd43", your_secret_key), but you sent "18cbdd666d74b735dde79edbeaf32df3a6fd1d255d97f09cc31af445b61c0169"
 {"exception":"[object] (Illuminate\\Broadcasting\\BroadcastException(code: 0): Invalid signature: you should have sent HmacSHA256Hex(\"POST\
/apps/567300/events\
auth_key=ed4ae6670d7eff5270f2&auth_timestamp=1532578885&auth_version=1.0&body_md5=f46404ebd0c36f7d62d1b51ebb85fd43\", your_secret_key), but you sent \"18cbdd666d74b735dde79edbeaf32df3a6fd1d255d97f09cc31af445b61c0169\"
 at /home/oza/lab/php/Client1_GestionCommerce/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:116)
[stacktrace]

Does anyone have a solution on that because I search on the internet and I can not find anything



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire