WAMP Protocol
Web Application Messaging Protocol — unified Remote Procedure Calls (RPC) and Publish/Subscribe (PubSub) in a single protocol over WebSocket.
Web Application Messaging Protocol — unified Remote Procedure Calls (RPC) and Publish/Subscribe (PubSub) in a single protocol over WebSocket.
WAMP combines two core messaging patterns — RPC and PubSub — into a single, unified protocol running over WebSocket.
Most real-time applications need both request-response (RPC) and event notification (PubSub) patterns. WAMP provides both in a single protocol, eliminating the need to combine multiple messaging systems. A WAMP router manages realms (isolation domains) and sessions, routing procedure calls to callees and events to subscribers. sgcWebSockets implements the WAMP Basic and Advanced profiles, supporting authentication, progressive results, and caller/callee identification.
Two messaging patterns, one protocol, infinite possibilities.
Register procedures on one client and call them from another. The WAMP router handles routing, load balancing, and result delivery.
Subscribe to topics and receive real-time events. Publishers and subscribers are fully decoupled through the WAMP router.
A central WAMP router manages all message routing, enabling clean separation between application components.
Realms provide isolation domains for multi-tenant applications. Sessions manage client lifecycle within realms.
Built-in support for ticket-based authentication and Challenge-Response Authentication (CRA) for secure session establishment.
Long-running RPC calls can return intermediate results progressively, keeping clients informed during processing.
Optionally identify the caller when making RPC calls, enabling authorization and auditing at the application level.
Applications that benefit from unified RPC and PubSub messaging.
Build live dashboards that receive real-time data updates via PubSub and fetch on-demand data through RPC calls.
Enable real-time collaborative document editing with PubSub for change notifications and RPC for conflict resolution.
Orchestrate microservices with RPC for service-to-service calls and PubSub for event-driven communication.
Manage IoT devices with RPC for command execution and PubSub for telemetry data streaming.
Build game backends with RPC for game actions and PubSub for real-time game state broadcasts to all players.
Connect to a WAMP router, register procedures, and subscribe to topics.
uses
sgcWebSocket_Client, sgcWebSocket_Types;
var
WSClient: TsgcWebSocketClient;
procedure TForm1.FormCreate(Sender: TObject);
begin
WSClient := TsgcWebSocketClient.Create(nil);
WSClient.Host := 'router.example.com';
WSClient.Port := 8080;
// Enable WAMP protocol
WSClient.WAMP.Enabled := True;
WSClient.WAMP.Realm := 'myapp';
// Set up event handlers
WSClient.OnWAMPWelcome := OnWAMPWelcome;
WSClient.OnWAMPEvent := OnWAMPEvent;
WSClient.OnWAMPResult := OnWAMPResult;
end;
procedure TForm1.ButtonConnectClick(Sender: TObject);
begin
WSClient.Active := True;
end;
procedure TForm1.OnWAMPWelcome(Sender: TObject;
aSession: Int64);
begin
// Subscribe to a topic
WSClient.WAMP.Subscribe('com.myapp.updates');
// Register a procedure that others can call
WSClient.WAMP.&Register('com.myapp.getStatus');
end;
procedure TForm1.OnWAMPEvent(Sender: TObject;
aSubscriptionId: Int64; aTopic, aDetails: string);
begin
// Handle PubSub events
Memo1.Lines.Add('Event: ' + aTopic + ' - ' + aDetails);
end;
procedure TForm1.ButtonCallClick(Sender: TObject);
begin
// Call a remote procedure
WSClient.WAMP.Call('com.myapp.calculate',
'[42, 58]');
end;
procedure TForm1.ButtonPublishClick(Sender: TObject);
begin
// Publish an event to a topic
WSClient.WAMP.Publish('com.myapp.updates',
'{"type": "status", "value": "online"}');
end;
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.