IIO Pub/Sub Messaging System
IntraIOManager • TopicTree Pattern Matching • Zero Module Coupling
Example: Player Movement Message Flow
PlayerModule
Game Logic
io.publish(
"player:position",
{x: 100, y: 200})
publish
IntraIOManager
Message Router + TopicTree
TopicTree Pattern Matching:
player:
position
health
score
Matched Subscribers:
1. "player:position" → UIModule
2. "player:*" → CollisionModule
3. "*" → MetricsModule
⚡ O(k) matching where k = topic depth
Sub-millisecond routing • Lock-free design
UIModule
User Interface
subscribed:
"player:position"
match ✓
CollisionModule
Physics
subscribed:
"player:*"
match ✓
MetricsModule
Analytics
subscribed:
"*" (all topics)
match ✓
Code Example: Complete Pub/Sub Flow
1. Publisher (PlayerModule):
// Create message data
auto data = std::make_unique<JsonDataNode>("position");
data->setDouble("x", playerX);
data->setDouble("y", playerY);
data->setDouble("vx", velocityX);
io->publish("player:position", std::move(data));
2. Subscriber (UIModule):
// Subscribe to topic pattern
io->subscribe("player:position");
// In process() loop:
while (io->hasMessages()) {
auto msg = io->pullMessage();
updatePlayerUI(msg.data);
}
3. Wildcard Pattern Examples:
"player:position" → Exact match only
"player:*" → Matches player:position, player:health, player:score
"render:*" → Matches render:sprite, render:text, render:clear
"*" → Matches ALL topics (use for logging/metrics)
"ui:button:*" → Matches ui:button:click, ui:button:hover
Performance
Routing time:
< 0.1ms
Pattern match complexity:
O(k)
k = topic depth (e.g., 2 for "player:pos")
Benefits
✓ Zero module coupling
✓ Easy to add/remove modules
✓ Dynamic subscriptions at runtime
✓ Thread-safe message queuing
IIO enables complete module decoupling • Add/remove modules without changing existing code