Skip to main content

PubSocket

Struct PubSocket 

Source
pub struct PubSocket<T: Transport<A>, A: Address> { /* private fields */ }
Expand description

A publisher socket. This is thread-safe and can be cloned.

Publisher sockets are used to publish messages under certain topics to multiple subscribers.

§Session

Per subscriber, the socket maintains a session. The session manages the underlying connection and all of its state, such as the topic subscriptions. It also manages a queue of messages to be transmitted on the connection.

Implementations§

Source§

impl<T> PubSocket<T, SocketAddr>

Source

pub async fn bind(&mut self, addr: impl ToSocketAddrs) -> Result<(), PubError>

Binds the socket to the given socket address.

This method is only available for transports that support SocketAddr as address type, like Tcp and Quic.

Source§

impl<T> PubSocket<T, PathBuf>
where T: Transport<PathBuf>,

Source

pub async fn bind(&mut self, path: impl Into<PathBuf>) -> Result<(), PubError>

Binds the socket to the given path.

This method is only available for transports that support PathBuf as address type, like Ipc.

Source§

impl<T, A> PubSocket<T, A>
where T: Transport<A>, A: Address,

Source

pub fn new(transport: T) -> Self

Creates a new reply socket with the default PubOptions.

Source

pub fn with_options(transport: T, options: PubOptions) -> Self

Creates a new publisher socket with the given transport and options.

Source

pub fn with_compressor<C: Compressor + 'static>(self, compressor: C) -> Self

Sets the message compressor for this socket.

Source

pub fn with_connection_hook<H>(self, hook: H) -> Self
where H: ConnectionHook<T::Io>,

Sets the connection hook for this socket.

The connection hook is called when a new connection is accepted, before the connection is used for pub/sub communication.

§Panics

Panics if the socket has already been bound (driver started).

Source

pub async fn try_bind(&mut self, addresses: Vec<A>) -> Result<(), PubError>

Binds the socket to the given addresses in order until one succeeds.

This also spawns the socket driver task.

Source

pub async fn publish( &self, topic: impl Into<String>, message: Bytes, ) -> Result<(), PubError>

Publishes a message to the given topic. If the topic doesn’t exist, this is a no-op.

Source

pub fn try_publish(&self, topic: String, message: Bytes) -> Result<(), PubError>

Publishes a message to the given topic, compressing the payload if a compressor is set. If the topic doesn’t exist, this is a no-op.

Source

pub fn stats(&self) -> &PubStats

Source

pub fn local_addr(&self) -> Option<&A>

Returns the local address this socket is bound to. None if the socket is not bound.

Trait Implementations§

Source§

impl<T: Clone + Transport<A>, A: Clone + Address> Clone for PubSocket<T, A>
where T::Io: Clone,

Source§

fn clone(&self) -> PubSocket<T, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, A> Freeze for PubSocket<T, A>
where T: Freeze, A: Freeze,

§

impl<T, A> !RefUnwindSafe for PubSocket<T, A>

§

impl<T, A> Send for PubSocket<T, A>

§

impl<T, A> Sync for PubSocket<T, A>

§

impl<T, A> Unpin for PubSocket<T, A>

§

impl<T, A> UnsafeUnpin for PubSocket<T, A>
where T: UnsafeUnpin, A: UnsafeUnpin,

§

impl<T, A> !UnwindSafe for PubSocket<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SpanExt<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more