Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel reverb doesn't work in the local development environment #286

Open
breno-ribeiro706 opened this issue Dec 20, 2024 · 1 comment
Open

Comments

@breno-ribeiro706
Copy link

breno-ribeiro706 commented Dec 20, 2024

Reverb Version

1.4

Laravel Version

11.0

PHP Version

8,3

Description

I'm experiencing an issue where Laravel Reverb is not triggering events when called. The event appears to be processed by the queue worker but doesn't show up in the Reverb terminal.

.env Configuration

BROADCAST_DRIVER=reverb
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=237641
REVERB_APP_KEY=28gciw5trm4wbncyiyoe
REVERB_APP_SECRET=z8ufizq2lwwyk9yhqmhm
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http

BroadcastServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Broadcast::routes();
        require base_path('routes/channels.php');
    }
}

channels

<?php
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('chat', function ($user) {
    return true;
});

broadcasting.php Configuration

'connections' => [
    'reverb' => [
        'driver' => 'reverb',
        'app_id' => env('REVERB_APP_ID'),
        'key' => env('REVERB_APP_KEY'),
        'secret' => env('REVERB_APP_SECRET'),
        'app_host' => env('REVERB_HOST', '127.0.0.1'),
        'app_port' => env('REVERB_PORT', 8080),
        'client_host' => env('REVERB_CLIENT_HOST', '127.0.0.1'),
        'client_port' => env('REVERB_CLIENT_PORT', 8080),
        'scheme' => env('REVERB_SCHEME', 'http'),
        'path' => env('REVERB_PATH', '/reverb'),
        'options' => [
            'cluster' => env('REVERB_APP_CLUSTER', 'mt1'),
            'useTLS' => env('REVERB_USE_TLS', false),
            'host' => env('REVERB_HOST', '127.0.0.1'),
            'port' => env('REVERB_PORT', 8080),
            'scheme' => env('REVERB_SCHEME', 'http'),
        ],
    ],
]

Route Definition

Route::get('/broadcast', function () {
    broadcast(new Example());
    return response()->json(['status' => 'Event broadcasted']);
});

Event Class (Example.php)

<?php

namespace App\Events;

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

class Example implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct()
    {
    }

    public function broadcastOn(): array
    {
        \Log::info('Broadcasting on chat channel');
        return [
            new Channel('chat')
        ];
    }

    public function broadcastWith(): array
    {
        return [
            'message' => 'Test message',
            'time' => now()->toDateTimeString()
        ];
    }
}

Current Behavior

When hitting the /broadcast endpoint, the queue worker processes the job:

php artisan queue:work
INFO Processing jobs from the [default] queue.  
2024-12-20 06:10:01 App\Events\Example ................................................. RUNNING
[2024-12-20 06:10:01] local.INFO: Broadcasting on chat channel  
2024-12-20 06:10:01 App\Events\Example ............................................ 37.51ms DONE

However, the Reverb terminal shows no events being broadcasted.

What I've Tried

  • Reinstalling the library
  • Verifying all configuration settings
  • Ensuring the queue worker is running

Steps To Reproduce

php artisan reverb:start

@joedixon
Copy link
Collaborator

joedixon commented Dec 20, 2024

Hi @breno-ribeiro706, can you try running

php artisan reverb:start --debug

Nothing will be output to the terminal outside of debug mode to preserve memory usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants