pub struct Segment { /* private fields */ }Expand description
A handle for one segment of a channel. It holds only its id:
subscriptions, listeners and the connection belong to the channel, so any
number of handles for one segment share them. Obtain one with
Channel::segment or
Channel::default_segment.
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn subscribe(&self) -> Result<Subscription, CelerisError>
pub fn subscribe(&self) -> Result<Subscription, CelerisError>
Registers interest in the segment’s messages. The first interest in a segment subscribes it, and it stays subscribed until every interest is cancelled; subscriptions are restored after every reconnect. The default segment is joined automatically and never subscribed or unsubscribed.
A subscription needs read access to the segment. No acknowledgement
exists: a denial arrives later, as a PermissionDeniedError, through
ChannelEventHandler::on_error.
It fails with CelerisError::NotConnected once the channel is closing
or closed.
Sourcepub fn subscribe_presence(&self) -> Result<Subscription, CelerisError>
pub fn subscribe_presence(&self) -> Result<Subscription, CelerisError>
Registers interest in the segment’s presence joins and leaves. Watching presence is not membership: it delivers no messages, and the watcher is not itself announced or listed.
Sourcepub fn on_message(
&self,
listener: impl Fn(&[u8], &MessageMetadata) + Send + Sync + 'static,
) -> Registration
pub fn on_message( &self, listener: impl Fn(&[u8], &MessageMetadata) + Send + Sync + 'static, ) -> Registration
Registers a listener for the segment’s deliveries. Each message id is delivered once within a bounded window (REV-01).
Sourcepub fn on_presence(
&self,
listener: impl Fn(&PresenceEvent) + Send + Sync + 'static,
) -> Registration
pub fn on_presence( &self, listener: impl Fn(&PresenceEvent) + Send + Sync + 'static, ) -> Registration
Registers a listener for joins and leaves. Events arrive only while a presence subscription is held: the server sends them to presence subscribers alone (PRES-01).
Sourcepub async fn publish(
&self,
payload: impl AsRef<[u8]>,
) -> Result<(), CelerisError>
pub async fn publish( &self, payload: impl AsRef<[u8]>, ) -> Result<(), CelerisError>
Sends payload to the segment with a generated message id. It returns
once the socket accepted the bytes. That is not receipt, delivery or
durability: the protocol has no acknowledgements.
A publish needs write access and does not join the segment. To receive
from the segment, your own publishes included, call
subscribe.
While the channel reconnects, the publish waits in the queue and is sent
after the reconnect, once the restored subscriptions have gone out. It
then fails with the error that
on_error reports if recovery
stops in Failed, and with
CelerisError::Cancelled if the channel closes.
It fails with CelerisError::NotConnected before the first connect,
while connecting, and once failed or closed; with
CelerisError::Backpressure when the publish queue (64 by default) is
already full; and with CelerisError::DeliveryUnknown when the socket
failed during the write, which is never resent. The plan’s cap counts
the whole encoded command, not only the payload. A publish over it
still succeeds here and is refused afterwards with a
MessageSizeLimitError through on_error.
Dropping the returned future takes the publish back if the socket has not started to write it.
Sourcepub async fn publish_with_message_id(
&self,
payload: impl AsRef<[u8]>,
message_id: &str,
) -> Result<(), CelerisError>
pub async fn publish_with_message_id( &self, payload: impl AsRef<[u8]>, message_id: &str, ) -> Result<(), CelerisError>
Segment::publish with your own message id. Receivers drop a repeated
id within their deduplication window, so reuse an id only to resend the
same message.
Sourcepub async fn presence_list(
&self,
page: i32,
per_page: i32,
) -> Result<PresencePage, CelerisError>
pub async fn presence_list( &self, page: i32, per_page: i32, ) -> Result<PresencePage, CelerisError>
One page of the segment’s presence. One query may be in flight per
channel; it fails with CelerisError::OperationInProgress while
another is pending, and with CelerisError::Timeout after the
presence query timeout. page starts at 1, and per_page is 1 to 100.
Dropping the returned future frees the query slot.