Publisher & Subscriber System

using Broadcast, Events, Job, Realtime Notification, Queue

NB: The Subscriber repo is added as a submodule to this, link above.

NB: pusher app key & secret in .env file could be any random value and doesn't link to my live account


Requirements / Tools => Docker, VS code, Sequel Ace


Using docker to run the setup

Both servers are laravel based. copies of the subscriber server can used for multiple tests


To create multiple subscriber server and adjust the environment

cp -r subscriber subscriber2


Setup

  • git clone the repos

  • cp .env.docker to .env => rename the .env.docker file for each server

  • set APP_PORT, VITE_PORT, DOCKER_APP_URL and FORWARD_ values in the .env file for new server in case of multiple system

Optional if switching user to sail to work in container environment, add WWWUSER and WWWGROUP. NB default is set as root

su - sail

switch to /var/www/html

cd /var/www/html

start Publisher terminal => both servers work using database for queue setup

php artisan queue:work

npm run dev

start Subscriber terminal

php artisan queue:work

npm run dev

php artisan websockets:serve


127.0.0.1:8000 for Publisher server

127.0.0.1:9000 for Subscriber server 1


Extra info

Open each server folder in terminal, install packages then sail up

composer install && npm run dev && ./vendor/bin/sail up -d


To send notification from publisher on a separate terminal

php artisan queue:work

start websocket for subscriber alone

php artisan websockets:serve

install and run blade in dev mode

pnpm i && pnpm run dev # NB pnpm is used here just like npm or yarn

To stop process, close from docker or open required server folder in terminal, then sail down

./vendor/bin/sail down

test subscriber event in tinker

php artisan tinker

event (new \App\Events\NewTrade('new'))