TopicManager provides centralized management for publishers and subscribers with automatic discovery, shared session management, and type safety validation.
TopicManager is especially useful when you have multiple publishers and subscribers. It reduces resource overhead and simplifies connection management.
To force network transport (useful for remote subscribers):
Copy
Ask AI
// Force network mode to simulate remote subscriberlet remote_subscriber = manager.register_subscriber::<SensorData>( "sensors/temperature", Some(true) // Force network)?;// Publisher's network will auto-enable via discovery protocol// Wait briefly for discovery to propagatestd::thread::sleep(std::time::Duration::from_secs(1));// Network should now be enabled// (In real code, check publisher.is_network_enabled())
There’s a brief delay (typically < 1 second) between subscriber creation and network enable. This is normal and allows the discovery protocol to propagate.
TopicManager ensures type safety by validating that all publishers and subscribers for a topic use the same message type:
Copy
Ask AI
#[derive(Copy, Clone, Debug)]#[repr(C)]struct SensorData { temperature: f32,}#[derive(Copy, Clone, Debug)]#[repr(C)]struct DifferentType { value: u64,}// First registration establishes the typelet pub1 = manager.register_publisher::<SensorData>("topic", false)?;// This will fail - type mismatch!match manager.register_publisher::<DifferentType>("topic", false) { Ok(_) => println!("Success"), Err(e) => println!("Error: {}", e), // "Type mismatch for topic 'topic'"}
Type safety prevents common errors like sending the wrong message type or mismatched field layouts. This is especially important for cross-language communication.
Keep-alive timeout is configurable per subscriber:
Copy
Ask AI
// DiscoveryMessage includes keep_alive_timeout_secs// Default is 60 seconds// This is set automatically by the subscriber
The 60-second timeout with 20-second keep-alive intervals provides a good balance between responsiveness and network efficiency. Subscribers that disconnect are detected within 60 seconds.
Publishers cannot be moved across threads due to iceoryx2’s internal single-threaded reference counting. Publishers must be used on the thread where they’re created.
If you need multi-threaded publishing, create separate publishers per thread or use synchronization primitives to coordinate access.
Cleanup runs every 10 seconds, so there’s up to 10s delay before network is disabled after the last subscriber disconnects.
This delay is intentional to avoid rapid enable/disable cycles when subscribers reconnect quickly. The 10-second cleanup interval provides a good balance.
// ✅ Good: Let TopicManager choose best transportlet subscriber = manager.register_subscriber::<T>("topic", None)?;// ⚠️ Only if you need specific behaviorlet subscriber = manager.register_subscriber::<T>("topic", Some(true))?;