Pub/Sub Messaging System
AfterLink features a high-performance publish/subscribe messaging engine baked directly into the socket protocol layer. Deliver real-time broad-scope channels with minimal wire steps.
How it Works
Unlike HTTP polling or traditional WebSockets where pub/sub routing must be written on top of JSON buffers in the application space, AfterLink utilizes dedicated message type bytes (MSG_SUBSCRIBE - 0x02 and MSG_PUBLISH - 0x03) to instruct the server on channel routing:
1. Client registers channel 0x02 (MSG_SUBSCRIBE) + "chat.global"
↓
2. Server stores registry map Sets Socket connection in channel memory array
↓
3. Message published 0x03 (MSG_PUBLISH) to "chat.global" -> server loops & relays header frames
Client Pub/Sub Code Example
Below is an implementation showing how simple it is to register subscribers and push events onto channels:
Channel Routing Patterns
AfterLink supports two levels of channel routing matching structures:
- Exact Matching: Routes messages only to subscribers bound to the exact string channel, such as
chat.room1. - Wildcard Routing (Single level): Using the asterisks character (
*), clients can subscribe to entire subgroups. For instance, subscribing tosensors.*catches broadcasts pushed tosensors.temperature,sensors.pressure, etc: