[−][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::{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 = "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 }; radio.transmit(msg, group).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);
Implementations
impl Dish
[src]
pub fn new() -> Result<Self, Error>
[src]
pub fn with_ctx(handle: CtxHandle) -> Result<Self, Error>
[src]
Create a Dish
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 join<G>(&self, group: G) -> Result<(), Error> where
G: Into<Group>,
[src]
G: Into<Group>,
Joins the specified group.
Usage Contract
- A group can be joined at most once.
Returned Error Variants
InvalidCtx
Interrupted
InvalidInput
(if group was already joined)
Example
use libzmq::{prelude::*, Dish, Group}; 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}; let first: Group = "group name".try_into()?; let dish = Dish::new()?; assert!(dish.joined().is_empty()); dish.join(first)?; assert_eq!(dish.joined().len(), 1);
pub fn leave<G>(&self, group: G) -> Result<(), Error> where
G: AsRef<GroupSlice>,
[src]
G: AsRef<GroupSlice>,
Leave the specified group.
Usage Contract
- The group must be already joined.
Returned Error Variants
InvalidCtx
Interrupted
InvalidInput
(if group not already joined)
Example
use libzmq::{prelude::*, Dish, Group}; 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 Clone for Dish
[src]
impl Debug for Dish
[src]
impl Eq for Dish
[src]
impl<'a> From<&'a Dish> for Pollable<'a>
[src]
impl PartialEq<Dish> for Dish
[src]
impl RecvMsg for Dish
[src]
fn recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
fn try_recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
fn recv_msg(&self) -> Result<Msg, Error>
[src]
fn try_recv_msg(&self) -> Result<Msg, Error>
[src]
fn recv_hwm(&self) -> Result<i32, Error>
[src]
fn set_recv_hwm(&self, hwm: i32) -> Result<(), Error>
[src]
fn recv_timeout(&self) -> Result<Period, Error>
[src]
fn set_recv_timeout<P>(&self, period: P) -> Result<(), Error> where
P: Into<Period>,
[src]
P: Into<Period>,
impl Send for Dish
[src]
impl Socket for Dish
[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 Sync for Dish
[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>,