[−][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<GroupOwned>,
[src]
I: IntoIterator<Item = G>,
G: Into<GroupOwned>,
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<GroupOwned>
[src]
Returns a snapshot of the list of joined Group
.
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(vec![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: Into<GroupOwned>,
[src]
I: IntoIterator<Item = G>,
G: Into<GroupOwned>,
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, GroupOwned}; use std::convert::TryInto; let group: GroupOwned = "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<Option<i32>, Error>
[src]
The high water mark for incoming messages on the specified socket. Read more
fn set_recv_high_water_mark(&self, maybe: Option<i32>) -> Result<(), Error>
[src]
Set the high water mark for inbound messages on the specified socket. Read more
fn recv_timeout(&self) -> Result<Option<Duration>, Error>
[src]
The timeout for [recv
] on the socket. Read more
fn set_recv_timeout(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
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 backlog(&self) -> Result<i32, Error>
[src]
Retrieve the maximum length of the queue of outstanding peer connections. Read more
fn set_backlog(&self, value: i32) -> Result<(), Error>
[src]
Set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports. Read more
fn heartbeat_interval(&self) -> Result<Duration, Error>
[src]
The interval between sending ZMTP heartbeats.
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
[src]
Sets the interval between sending ZMTP PINGs (aka. heartbeats). Read more
fn heartbeat_timeout(&self) -> Result<Duration, Error>
[src]
How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. Read more
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
[src]
How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. Read more
fn heartbeat_ttl(&self) -> Result<Duration, Error>
[src]
The timeout on the remote peer for ZMTP heartbeats. If this option and heartbeat_interval
is not None
the remote side shall time out the connection if it does not receive any more traffic within the TTL period. Read more
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
[src]
Set timeout on the remote peer for ZMTP heartbeats. If this option and heartbeat_interval
is not None
the remote side shall time out the connection if it does not receive any more traffic within the TTL period. Read more
fn linger(&self) -> Result<Option<Duration>, Error>
[src]
Returns the linger period for the socket shutdown.
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
Sets the linger period for the socket shutdown. 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
impl Sync 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 Eq for Dish
[src]
impl Debug for Dish
[src]
Blanket Implementations
impl<T> From<T> for T
[src]
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, 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> 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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,