Caution
Every payload you transmit with iceoryx2 must implement [ZeroCopySend] to
be compatible with shared memory.
Usually, you can use the derive-macro #[derive(ZeroCopySend)] for most
types. If you implement it manually you must ensure that the payload type:
- is self contained, no heap, no pointers to external sources
- has a uniform memory representation ->
#[repr(C)] - does not use pointers to manage their internal structure
- and its members don't implement
Dropexplicitly - has a
'staticlifetime
Data types like String or Vec will cause undefined behavior and may
result in segmentation faults. We provide alternative data types that are
compatible with shared memory. See the
complex data type example for guidance on how to
use them.
This example illustrates a robust publisher-subscriber messaging pattern
between two separate processes. The publisher sends a message every second,
each containing [TransmissionData]. On the receiving end, the subscriber
checks for new data every second.
The subscriber is printing the sample on the console whenever new data arrives.
To observe this dynamic communication in action, open two separate terminals and execute the following commands:
cargo run --example publish_subscribe_subscribercargo run --example publish_subscribe_publisherFeel free to run multiple instances of publisher or subscriber processes simultaneously to explore how iceoryx2 handles publisher-subscriber communication efficiently.
Tip
You may hit the maximum supported number of ports when too many publisher or subscriber processes run. Take a look at the iceoryx2 config to set the limits globally or at the API of the Service builder to set them for a single service.