Overview
TopicManager provides a centralized API for managing publishers and subscribers with automatic discovery, shared session management, and type safety. This reference documents all available methods organized by functionality.For a quick start guide with examples, see the Quickstart page.
Quick Reference
| Method | Description | Category |
|---|---|---|
create() | Create a new TopicManager instance | Initialization |
register_publisher() | Register a publisher for a topic | Publishing |
send_message() | Send a typed message to a topic | Publishing |
send() | Send raw bytes to a topic | Publishing |
register_subscriber() | Register a subscriber for a topic | Subscribing |
pull() | Pull the latest message (non-blocking) | Subscribing |
check_local_availability() | Check if local IPC is available | Advanced |
get_listener() | Get iceoryx2 listener for a topic | Advanced |
subscribe_to_topic() | Subscribe with callback function | Advanced |
request_to_broadcast() | Request topic broadcast from network | Advanced |
session() | Get shared Zenoh session | Advanced |
Initialization
create()
create()
Signature
Description
Creates a new TopicManager instance with a shared Zenoh session and iceoryx2 node. This is the entry point for all TopicManager operations.The manager automatically:- Initializes a shared Zenoh session for network operations
- Creates a shared iceoryx2 node for local IPC
- Starts the discovery thread for automatic subscriber detection
- Initializes the schema registry if schema directories exist
Returns
Ok(TopicManager)- Successfully created managerErr(e)- Error during initialization (e.g., Zenoh connection failed)
Example
Publishing Messages
register_publisher()
register_publisher()
Signature
Description
Registers a publisher for a topic. Returns a shared publisher handle that can be cloned for use across different parts of your application.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to publish to |
enable_network_initial | bool | If true, enables network publishing initially. If false, network is enabled automatically when remote subscribers are discovered |
is_variable_size | bool | If true, uses variable-size allocation for large messages. If false, uses fixed-size allocation (faster but limited) |
Returns
Ok(Arc<Publisher>)- Publisher handle for shared ownershipErr(e)- Error during publisher creation
Example
Notes
The
is_variable_size parameter affects memory allocation:false(fixed-size): Faster allocation, but limited message size. Use for small, frequent messages.true(variable-size): Slower allocation, but supports larger messages. Use when messages may exceed the fixed buffer size.
send_message()
send_message()
Signature
Description
Sends a typed message to a topic. The message is automatically serialized using itsto_bytes() implementation. This method provides compile-time type checking and automatic schema tracking.The method will:- Get or create a publisher for the topic
- Serialize the message to bytes
- Extract and track the schema name from the type
- Send the message via the publisher
Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to send to |
message | &T | Reference to a message that implements SerializableMessage |
Returns
Ok(())- Message sent successfullyErr(e)- Error during send (e.g., serialization failed, publisher error)
Example
See Also
send()- For sending raw bytes or pre-serialized data
send()
send()
Signature
Description
Sends raw bytes to a topic. Gets or creates a publisher for the topic and sends the data as-is. Use this when you already have serialized bytes or need to send data that doesn’t implementSerializableMessage.The schema name is automatically inferred from the message format if the data is already wrapped in a relocatable message.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to send to |
data | Vec<u8> | Raw bytes to send |
Returns
Ok(())- Message sent successfullyErr(e)- Error during send
Example
When to Use
Receiving Messages
register_subscriber()
register_subscriber()
Signature
Description
Registers a subscriber for a topic. Returns a thread-safe shared subscriber handle that can be cloned and used across threads.Thenetwork_mode parameter controls transport selection:None- Auto-detect: tries local first if available, falls back to networkSome(true)- Force network: always uses network transportSome(false)- Force local: only uses local IPC (fails if no local publisher exists)
Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to subscribe to |
network_mode | Option<bool> | Transport mode: None = auto-detect, Some(true) = force network, Some(false) = force local |
Returns
Ok(Arc<Mutex<Subscriber>>)- Thread-safe shared subscriber handleErr(e)- Error during subscriber creation
Example
Thread Safety
The returned Always lock the
Arc<Mutex<Subscriber>> can be safely shared across threads:Mutex before accessing the subscriber.Important
pull()
pull()
Signature
Description
Pulls the latest message from a topic’s subscriber. This method is always non-blocking - it returns immediately whether a message is available or not.Gets or creates a subscriber for the topic if it doesn’t exist, then returns the latest available message.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to pull from |
Returns
Ok(Some(bytes))- Message available, returns the message bytesOk(None)- No message currently availableErr(e)- Error occurred (e.g., subscriber error)
Example
Behavior
pull() never blocks. It always returns immediately with:Ok(Some(bytes))if a message is availableOk(None)if no message is availableErr(e)if an error occurred
std::thread::sleep or access the subscriber’s blocking receive methods directly.Advanced Operations
check_local_availability()
check_local_availability()
Signature
Description
Checks whether an iceoryx2 service is available for the given topic, which indicates that a local publisher exists. This is useful for determining if local IPC transport is available before creating a subscriber.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to check |
Returns
true- Local IPC service exists for the topicfalse- No local service available
Example
get_listener()
get_listener()
Signature
Description
Gets or creates an iceoryx2 listener for a topic. This will register a subscriber for the topic if it doesn’t exist. ReturnsNone if the subscriber is network-only (no local listener available).This method provides low-level access to iceoryx2’s event-driven API for advanced use cases.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to get listener for |
Returns
Ok(Some(listener))- Local listener availableOk(None)- Subscriber is network-only or local IPC not availableErr(e)- Error during listener creation
Example
When to Use
subscribe_to_topic()
subscribe_to_topic()
Signature
Description
Subscribes to topics with a callback function. When the trigger topic receives data, the callback is invoked with data collected from all input topics. The callback’s return value is published to the output topics.This is useful for creating data processing pipelines where one topic triggers processing of multiple input topics.Parameters
| Parameter | Type | Description |
|---|---|---|
callback | F | Function that accepts flatbuffer bytes from input topics and returns bytes for output topics |
io_dict | IODict | Dictionary containing input and output topic name vectors |
trigger_topic | &str | Topic name that triggers the callback when it receives data |
Returns
Ok(SubscriptionHandle)- Handle to manage the subscription lifecycleErr(e)- Error during subscription creation
Example
Important
request_to_broadcast()
request_to_broadcast()
Signature
Description
Requests a broadcast of all registered topics from other TopicManagers on the network. Subscribes to the broadcast channel and prints all received topic information.This is useful for discovering what topics are available on the network from other processes.Returns
Ok(())- Broadcast request sent and response receivedErr(e)- Error during broadcast (e.g., timeout waiting for response)
Example
Use Case
This method is useful for debugging and discovery. It helps you see what topics are available on the network from other TopicManager instances.
session()
session()
Signature
Description
Returns a reference to the shared Zenoh session used by all network operations. This provides direct access to Zenoh functionality if you need to perform operations not covered by TopicManager’s API.Returns
&Arc<zenoh::Session>- Reference to the shared Zenoh session