[][src]Struct libzmq::Dish

pub struct Dish { /* fields omitted */ }

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

CharacteristicValue
Compatible peer socketsRadio
DirectionUnidirectional
Send/receive patternReceive only
Incoming routing strategyFair-queued
Outgoing routing strategyN/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]

Joins the specified group.

Usage Contract

  • A group can be joined at most once.

Returned Error Variants

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]

Leave the specified group.

Usage Contract

  • The group must be already joined.

Returned Error Variants

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]

impl Send for Dish[src]

impl Socket for Dish[src]

impl Sync for Dish[src]

Auto Trait Implementations

impl RefUnwindSafe for Dish

impl Unpin for Dish

impl UnwindSafe for Dish

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,