Publish-Subscribe
A popular unidirectional, multi-producer, multi-consumer messaging pattern that decouples the producer (publisher) from the consumer (subscriber). This enables each participant to have their own lifecycle and operate completely independently. Publishers send messages without knowing who will receive them, while subscribers express interest in receiving payloads from a service and are automatically connected to matching publishers.
The publish-subscribe messaging pattern excels at communicating large payloads to multiple participants. The zero-copy capability enables essentially constant latency regardless of payload size.
The pattern is not optimal for cases where data must be kept available to participants indefinitely (blackboard) or when two-way communication is required (request-response).
Mechanism
The publish-subscribe messaging pattern is implemented using data structures in shared memory. The following structures are involved:
- Payload Segment
- A region in shared memory used to communicate payload data between participants
- Publishers have a payload segment to share samples with subscribers
- The organization of memory in the payload segment depends on the allocator used in the
iceoryx2deployment- This flexibility allows different deployments (e.g. desktop applications vs. safety-critical applications) to utilize a different strategy appropriate to their use-case
- Offset Channel
- A channel for communicating the offsets of payloads within the payload segment
- Each publisher-subscriber pair has their own offset channel
Further Reading
-
See how the
Eventmessaging pattern can be used to coordinate participants. -
Example: Publish-Subscribe Service
See how to set up a basic
PublishSubscribeservice. -
Example: Dynamic Publish-Subscribe Service
See how to set up a
PublishSubscribeservice with dynamic memory allocations.