I've implemented Laravel Websockets along with Echo in my local environment and everything is working, but when deploying to production, it appears a connection can be made and it's subscribed to the channels, but events do not fire. And I'm clueless about what I'm doing wrong.
Here's my setup:
.env
file:
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=someID
PUSHER_APP_KEY=someKey
PUSHER_APP_SECRET=someSecret
PUSHER_APP_CLUSTER=eu
PUSHER_SCHEME=http
PUSHER_USE_SSL=false
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUSHER_USE_SSL=true
MIX_PUSHER_HOST=mydomain.com
MIX_PUSHER_PORT=443
Echo
configuration:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: process.env.MIX_PUSHER_HOST,
wsPort: process.env.MIX_PUSHER_PORT,
forceTLS: process.env.MIX_PUSHER_USE_SSL === true || process.env.MIX_PUSHER_USE_SSL === 'true',
disableStats: true,
});
nginx
config:
location /app/ {
proxy_pass http://127.0.0.1:6001/app/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /apps/ {
proxy_pass http://127.0.0.1:6001/apps/;
proxy_set_header Host $host;
}
This is to set up a reverse proxy to be able to use my site's SSL
websockets.php
and broadcasting.php
are left with all default values.
On the websockets dashboard at /laravel-websockets
I am able to connect via port 443 and I can see it subscribed to my channels:
What I expect to see when an event should be triggered is something like this that I see in my local environment:
But this does not appear in production. As if it can subscribe to channels but not capture the api-message
events.
This is my first time implementing websockets so I'm a little lost. Anyone see what I'm doing wrong?
Ok, figured it out!
What I didn't realize but makes perfect sense is that these API messages that get broadcast are queued. And if your queue is not consuming correctly, you'll never see them.
In my local environment I used Laravel's sync
queue driver, so that's why it worked locally, but on in production due to a config error my RabbitMQ queue was not being consumed correctly.
Once I fixed that, everything started working as expected :)
Anyway maybe the configuration listed in my question will help someone else who's trying to figure out how to do this.