[−][src]Struct libzmq::Radio
A Radio
socket is used by a publisher to distribute data to Dish
sockets.
Each message sent belong to a group. By default, the group is "".
This group can be specified by using set_group
or using the convenience
method transmit
. Messages are distributed to all members of a group.
Mute State
When a Radio
socket enters the mute state due to having reached the
high water mark for a subscriber, then any messages that would be sent to
the subscriber in question shall instead be dropped until the mute state ends.
Summary of Characteristics
Characteristic | Value |
---|---|
Compatible peer sockets | Dish |
Direction | Unidirectional |
Send/receive pattern | Send only |
Incoming routing strategy | N/A |
Outgoing routing strategy | Fan out |
Action in mute state | Drop |
Example
use libzmq::{prelude::*, *}; use std::{thread, time::Duration}; let addr: TcpAddr = "127.0.0.1:*".try_into()?; let radio = RadioBuilder::new() .bind(addr) .build()?; let bound = radio.last_endpoint()?; let a: Group = "A".try_into()?; let b: Group = "B".try_into()?; let dish_a = DishBuilder::new() .connect(&bound) .join(&a) .build()?; let dish_b = DishBuilder::new() .connect(bound) .join(&b) .build()?; // Start the feed. It has no conceptual start nor end, thus we // don't synchronize with the subscribers. thread::spawn(move || { let a: Group = "A".try_into().unwrap(); let b: Group = "B".try_into().unwrap(); let mut count = 0; loop { let msg = Msg::new(); // Alternate between the two groups. let group = if count % 2 == 0 { &a } else { &b }; radio.transmit(msg, group).unwrap(); thread::sleep(Duration::from_millis(1)); count += 1; } }); // Each dish will only receive the messages from their respective groups. let msg = dish_a.recv_msg()?; assert_eq!(msg.group().unwrap(), &a); let msg = dish_b.recv_msg()?; assert_eq!(msg.group().unwrap(), &b);
Implementations
impl Radio
[src]
pub fn new() -> Result<Self, Error>
[src]
pub fn with_ctx(handle: CtxHandle) -> Result<Self, Error>
[src]
Create a Radio
socket associated with a specific context
from a CtxHandle
.
Returned Error Variants
pub fn ctx(&self) -> CtxHandle
[src]
Returns a reference to the context of the socket.
pub fn no_drop(&self) -> Result<bool, Error>
[src]
Returns true
if the no_drop
option is set.
pub fn set_no_drop(&self, enabled: bool) -> Result<(), Error>
[src]
Sets the socket's behaviour to block instead of drop messages when
in the mute state
.
Default value
false
pub fn transmit<M, G>(&self, msg: M, group: G) -> Result<(), Error<Msg>> where
M: Into<Msg>,
G: AsRef<GroupSlice>,
[src]
M: Into<Msg>,
G: AsRef<GroupSlice>,
Push a message into the outgoing socket queue with the specified group.
This is a convenience function that sets the Msg
's group then
sends it.
See send
for more information.
pub fn try_transmit<M, G>(&self, msg: M, group: G) -> Result<(), Error<Msg>> where
M: Into<Msg>,
G: AsRef<GroupSlice>,
[src]
M: Into<Msg>,
G: AsRef<GroupSlice>,
Try to push a message into the outgoing socket queue with the specified group.
This is a convenience function that sets the Msg
's group then
tries sends it.
See try_send
for more information.
Trait Implementations
impl Clone for Radio
[src]
impl Debug for Radio
[src]
impl Eq for Radio
[src]
impl<'a> From<&'a Radio> for Pollable<'a>
[src]
impl PartialEq<Radio> for Radio
[src]
impl Send for Radio
[src]
impl SendMsg for Radio
[src]
fn send<M>(&self, msg: M) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
fn try_send<M>(&self, msg: M) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
fn send_hwm(&self) -> Result<i32, Error>
[src]
fn set_send_hwm(&self, hwm: i32) -> Result<(), Error>
[src]
fn send_timeout(&self) -> Result<Period, Error>
[src]
fn set_send_timeout<P>(&self, period: P) -> Result<(), Error> where
P: Into<Period>,
[src]
P: Into<Period>,
impl Socket for Radio
[src]
fn connect<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn bind<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn disconnect<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn unbind<I, E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Endpoint, Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
impl StructuralEq for Radio
[src]
impl StructuralPartialEq for Radio
[src]
impl Sync for Radio
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,