[−][src]Struct libzmq::Dish
A Dish
socket is used by a subscriber to subscribe to groups distributed
by a Radio
.
Initially a ZMQ_DISH socket is not subscribed to any groups, use join
to join a group.
Summary of Characteristics
Characteristic | Value |
---|---|
Compatible peer sockets | Radio |
Direction | Unidirectional |
Send/receive pattern | Receive only |
Incoming routing strategy | Fair-queued |
Outgoing routing strategy | N/A |
Example
use libzmq::{prelude::*, *}; use std::{convert::TryInto, thread, time::Duration}; let addr: TcpAddr = "127.0.0.1:*".try_into()?; let radio = RadioBuilder::new() .bind(addr) .build()?; let bound = radio.last_endpoint().unwrap(); let a: Group = "group a".try_into()?; let dish = DishBuilder::new() .connect(bound) .join(&a) .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 = "group a".try_into().unwrap(); let b: Group = "group b".try_into().unwrap(); let mut count = 0; loop { let mut msg = Msg::new(); // Alternate between the two groups. let group = if count % 2 == 0 { &a } else { &b }; msg.set_group(group); radio.send(msg).unwrap(); thread::sleep(Duration::from_millis(1)); count += 1; } }); // The dish exclusively receives messages from the groups it joined. let msg = dish.recv_msg()?; assert_eq!(msg.group().unwrap(), &a); let msg = dish.recv_msg()?; assert_eq!(msg.group().unwrap(), &a);
Methods
impl Dish
[src]
pub fn new() -> Result<Self, Error>
[src]
pub fn with_ctx<C>(ctx: C) -> Result<Self, Error> where
C: Into<Ctx>,
[src]
C: Into<Ctx>,
pub fn ctx(&self) -> &Ctx
[src]
Returns a reference to the context of the socket.
pub fn join<I, G>(&self, groups: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = G>,
G: Into<Group>,
[src]
I: IntoIterator<Item = G>,
G: Into<Group>,
Joins the specified group(s).
When any of the connection attempt fail, the Error
will contain the position
of the iterator before the failure. This represents the number of
groups that were joined before the failure.
Usage Contract
- Each group can be joined at most once.
Returned Error Variants
CtxTerminated
Interrupted
InvalidInput
(if group was already joined)
Example
use libzmq::{prelude::*, Dish, Group}; use std::convert::TryInto; let group: Group = "some group".try_into()?; let dish = Dish::new()?; dish.join(group)?;
pub fn joined(&self) -> Vec<Group>
[src]
Returns a snapshot of the list of joined groups.
The list might be modified by another thread after it is returned.
Example
use libzmq::{prelude::*, Dish, Group}; use std::convert::TryInto; let first: Group = "first group".try_into()?; let second: Group = "second group".try_into()?; let dish = Dish::new()?; assert!(dish.joined().is_empty()); dish.join(&[first, second])?; assert_eq!(dish.joined().len(), 2);
pub fn leave<I, G>(&self, groups: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = G>,
G: AsRef<GroupSlice>,
[src]
I: IntoIterator<Item = G>,
G: AsRef<GroupSlice>,
Leave the specified group(s).
When any of the connection attempt fail, the Error
will contain the position
of the iterator before the failure. This represents the number of
groups that were leaved before the failure.
Usage Contract
- The group must be already joined.
Returned Error Variants
CtxTerminated
Interrupted
InvalidInput
(if group not already joined)
Example
use libzmq::{prelude::*, Dish, Group}; use std::convert::TryInto; let group: Group = "some group".to_owned().try_into()?; let dish = Dish::new()?; assert!(dish.joined().is_empty()); dish.join(&group)?; assert_eq!(dish.joined().len(), 1); dish.leave(&group)?; assert!(dish.joined().is_empty());
Trait Implementations
impl RecvMsg for Dish
[src]
fn recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
Retreive a message from the inbound socket queue. Read more
fn try_recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
Try to retrieve a message from the inbound socket queue without blocking. Read more
fn recv_msg(&self) -> Result<Msg, Error>
[src]
A convenience function that allocates a [Msg
] with the same properties as [recv
]. Read more
fn try_recv_msg(&self) -> Result<Msg, Error>
[src]
A convenience function that allocates a [Msg
] with the same properties as [try_recv
]. Read more
fn recv_high_water_mark(&self) -> Result<Quantity, Error>
[src]
The high water mark for incoming messages on the specified socket. Read more
fn set_recv_high_water_mark<Q>(&self, qty: Q) -> Result<(), Error> where
Q: Into<Quantity>,
[src]
Q: Into<Quantity>,
Set the high water mark for inbound messages on the specified socket. Read more
fn recv_timeout(&self) -> Result<Period, Error>
[src]
The timeout for [recv
] on the socket. Read more
fn set_recv_timeout<P>(&self, period: P) -> Result<(), Error> where
P: Into<Period>,
[src]
P: Into<Period>,
Sets the timeout for [recv
] on the socket. Read more
impl Socket for Dish
[src]
fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
Schedules a connection to one or more [Endpoints
] and then accepts incoming connections. Read more
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
Disconnect the socket from one or more [Endpoints
]. Read more
fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
Schedules a bind to one or more [Endpoints
] and then accepts incoming connections. Read more
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
Unbinds the socket from one or more [Endpoints
]. Read more
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>
[src]
Retrieve the last endpoint connected or bound to. Read more
fn mechanism(&self) -> Mechanism
[src]
Returns the socket's [Mechanism
]. Read more
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
Set the socket's [Mechanism
]. # Example ``` # use failure::Error; # # fn main() -> Result<(), Error> { use libzmq::{prelude::, Client, auth::}; Read more
fn heartbeat(&self) -> Option<Heartbeat>
[src]
Returns a the socket's heartbeat configuration.
fn set_heartbeat(&self, maybe: Option<Heartbeat>) -> Result<(), Error>
[src]
Set the socket's heartbeat configuration. Read more
impl Sync for Dish
[src]
impl Eq for Dish
[src]
impl Send for Dish
[src]
impl PartialEq<Dish> for Dish
[src]
fn eq(&self, other: &Dish) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for Dish
[src]
fn clone(&self) -> Dish
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Dish
[src]
Blanket Implementations
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,