Overview
Publisher and Subscriber provide direct, low-level APIs for messaging in Cerulion Core. Unlike TopicManager, these APIs require manual session management, transport control, and serialization handling.For a quick start guide with examples, see the Quickstart page.
Quick Reference
| Method | Description | Category |
|---|---|---|
Publisher::create() | Create a new publisher | Initialization |
Publisher::create_with_session() | Create publisher with shared session/node | Initialization |
publisher.send() | Send raw bytes to topic | Publishing |
publisher.send_message() | Send typed message (convenience) | Publishing |
publisher.enable_network() | Enable network publishing | Network Control |
publisher.disable_network() | Disable network publishing | Network Control |
publisher.is_network_enabled() | Check if network is enabled | Network Control |
publisher.start_network_thread() | Start network thread manually | Network Control |
publisher.stop_network_thread() | Stop network thread manually | Network Control |
Subscriber::create() | Create a new subscriber | Initialization |
Subscriber::create_with_session() | Create subscriber with shared session/node | Initialization |
subscriber.receive() | Receive message (non-blocking) | Subscribing |
subscriber.enable_local_subscriber() | Enable local transport after creation | Subscribing |
subscriber.id() | Get subscriber ID | Utilities |
subscriber.take_listener() | Get iceoryx2 listener | Utilities |
Publisher API
create()
create()
Signature
Description
Creates a new publisher for a topic. The publisher always uses local (iceoryx2) transport. Network (Zenoh) transport can be enabled or disabled via theenable_network parameter.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to publish to |
enable_network | bool | If true, enables network publishing initially. If false, network can be enabled later with enable_network() |
Returns
Ok(Publisher)- Successfully created publisherErr(e)- Error during publisher creation
Example
The publisher handle must remain alive for subscribers to receive messages. If the publisher is dropped, local subscribers will stop receiving messages.
create_with_session()
create_with_session()
Signature
Description
Creates a publisher with an optional shared Zenoh session and iceoryx2 node. This allows you to reuse sessions and nodes across multiple publishers to reduce resource overhead.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to publish to |
enable_network | bool | If true, enables network publishing initially |
zenoh_session | Option<Arc<zenoh::Session>> | Optional shared Zenoh session. If None, creates a new session |
variable_size | bool | If true, uses variable-size allocation for large messages |
shared_node | Option<Arc<Node<ipc::Service>>> | Optional shared iceoryx2 node. If None, creates a new node |
Returns
Ok(Publisher)- Successfully created publisherErr(e)- Error during publisher creation
Example
send()
send()
Signature
Description
Sends raw bytes to the topic. The bytes are automatically wrapped in a relocatable message format (unless already in relocatable format from ROS2 hooks).Parameters
| Parameter | Type | Description |
|---|---|---|
data | &[u8] | Raw bytes to send |
Returns
Ok(())- Message sent successfullyErr(e)- Error during send
Behavior
When you callsend(), here’s what happens:- Relocatable wrapping: Raw bytes are wrapped in a relocatable message format (unless already in relocatable format)
- Local path: Message is written directly to shared memory (synchronous, fast, < 1 μs)
- Network path (if enabled): Message is queued to background thread (non-blocking)
- Background thread: Converts relocatable to protobuf and sends over Zenoh (asynchronous)
The network path uses latest-message semantics. If the network is slow and multiple messages arrive, only the most recent message is sent. This ensures network subscribers always get the latest data.
Example
send_message()
send_message()
Signature
Description
Convenience method that automatically serializes a typed message before sending. The message type must implementSerializableMessage.Parameters
| Parameter | Type | Description |
|---|---|---|
message | &T | Reference to a message that implements SerializableMessage |
Returns
Ok(())- Message sent successfullyErr(e)- Error during serialization or send
Example
enable_network()
enable_network()
disable_network()
disable_network()
is_network_enabled()
is_network_enabled()
start_network_thread()
start_network_thread()
Subscriber API
create()
create()
Signature
Description
Creates a new subscriber for a topic. The subscriber automatically chooses the best transport based on thenetwork_only parameter.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to subscribe to |
network_only | Option<bool> | Transport selection: None (auto-detect), Some(true) (network only), Some(false) (local only) |
Returns
Ok(Subscriber)- Successfully created subscriberErr(e)- Error during subscriber creation
Auto-Detection Logic
Whennetwork_only is None:- Check if local publisher exists (iceoryx2)
- If yes, use local transport (fast, zero-copy)
- If no, use network transport (Zenoh)
Example
create_with_session()
create_with_session()
Signature
Description
Creates a subscriber with an optional shared Zenoh session and iceoryx2 node. This allows you to reuse sessions and nodes across multiple subscribers to reduce resource overhead.Parameters
| Parameter | Type | Description |
|---|---|---|
topic | &str | Topic name to subscribe to |
network_only | Option<bool> | Transport selection: None (auto-detect), Some(true) (network only), Some(false) (local only) |
zenoh_session | Option<Arc<zenoh::Session>> | Optional shared Zenoh session. If None, creates a new session |
shared_node | Option<Arc<Node<ipc::Service>>> | Optional shared iceoryx2 node. If None, creates a new node |
Returns
Ok(Subscriber)- Successfully created subscriberErr(e)- Error during subscriber creation
Example
receive()
receive()
Signature
Description
Receives a message from the topic. This method is non-blocking and returns raw bytes that you must deserialize yourself.Returns
Ok(Some(bytes))- Message received (raw bytes)Ok(None)- No message availableErr(e)- Error during receive
The
receive() method never blocks. It returns immediately with Some(Vec<u8>) if a message is available, or None if no message is ready.Behavior
The method checks transport in this order:- Local transport (if available): Checks iceoryx2 shared memory first (fastest)
- Network transport (if available): Checks Zenoh network messages
Example
enable_local_subscriber()
enable_local_subscriber()
Signature
Description
Enables local subscriber transport after creation. This is useful if you created a network-only subscriber but later want to also receive from local publishers.Parameters
| Parameter | Type | Description |
|---|---|---|
shared_node | Option<Arc<Node<ipc::Service>>> | Optional shared iceoryx2 node. If None, creates a new node |
Returns
Ok(())- Local subscriber enabled successfullyErr(e)- Error during local subscriber creation (e.g., publisher doesn’t exist yet)
Example
id()
id()
take_listener()
take_listener()
Signature
Description
Takes the local listener from the subscriber. This consumes the listener from the subscriber, so it can only be called once. The listener can be used for event-based notifications from the local publisher.Returns
Some(listener)- Local listener if availableNone- No local listener available (network-only subscriber)