Skip to main content

WebSocket Proxy Service

The WebSocket Proxy service enables real-time communication between the server and client applications. It handles live notifications, real-time data updates, and push events for the Tenant Frontend.

Architecture

  Tenant Frontend (Browser)
│ WebSocket (wss://)

WS Proxy Backend (Laravel 12)

├──▶ Redis (pub/sub, channel state)
├──▶ RabbitMQ (event consumption)
└──▶ PostgreSQL (channel auth)

Key Features

Real-Time Channels

  • Private channels — Authenticated user-specific events
  • Presence channels — Track who's online (e.g., admin dashboard)
  • Public channels — Broadcast events to all connected clients

Event Types

  • Order status updates (real-time tracking)
  • Stock level changes (live inventory)
  • New customer notifications
  • System alerts and announcements
  • Dashboard live data refresh

Connection Management

  • WebSocket upgrade from HTTP
  • Automatic reconnection handling
  • Connection heartbeat and timeout
  • Per-user channel authorization

How It Works

  1. Frontend opens WebSocket connection to WS Proxy
  2. User subscribes to channels (e.g., orders.{tenant_id})
  3. WS Proxy verifies authorization via Identity service
  4. Backend services publish events to RabbitMQ
  5. WS Proxy consumes events and broadcasts to subscribers
Backend Service ──▶ RabbitMQ ──▶ WS Proxy ──▶ Browser (WebSocket)

Client Integration

Frontend (Vue 3)

import Echo from 'laravel-echo';
import Pusher from 'pusher-js';

const echo = new Echo({
broadcaster: 'pusher',
wsHost: '{tenant}.vecton.hu',
wsPort: 443,
wssPort: 443,
forceTLS: true,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});

// Listen for order updates
echo.private(`orders.${tenantId}`)
.listen('OrderStatusChanged', (event) => {
console.log('Order updated:', event.order);
});

// Presence channel (who's online)
echo.join(`dashboard.${tenantId}`)
.here((users) => console.log('Online:', users))
.joining((user) => console.log('Joined:', user))
.leaving((user) => console.log('Left:', user));

Channels

Channel PatternTypeDescription
orders.{tenantId}PrivateOrder status updates
stock.{tenantId}PrivateStock level changes
notifications.{userId}PrivateUser notifications
dashboard.{tenantId}PresenceAdmin dashboard users
announcementsPublicSystem-wide broadcasts

API Endpoints

Base URL: https://{tenant}.vecton.hu/api/ws (production) | http://localhost:8015/api (dev)

MethodEndpointDescription
GET/broadcasting/authChannel authorization
POST/broadcasting/authAuthenticate private/presence channel
GET/healthWebSocket server health check

Configuration

VariableDescriptionDefault
APP_URLService base URLhttp://localhost:8015
DB_SCHEMADatabase schemaws_proxy
BROADCAST_DRIVERLaravel broadcast driverpusher
PUSHER_APP_IDPusher/Soketi app IDapp-id
PUSHER_APP_KEYPusher/Soketi app keyapp-key
PUSHER_APP_SECRETPusher/Soketi secretapp-secret

Development

cd tenant/tenant-backend-ws-proxy
composer install
php artisan migrate
php artisan serve --port=8015