pub struct PersistentSubscriptionBuilder { /* private fields */ }Expand description
Builder for configuring and creating a persistent subscription. This provides a fluent interface for setting up a persistent subscription with proper CString handling.
The subscription keeps the Aeron client and archive context given here open until it
closes. Building also points the archive context at the subscription’s client, so
build with Self::new_with_aeron, which sets one client on both, as below. Without
a client, the subscription makes its own and closes it when it closes, after which the
context must not be used to connect again.
§Examples
use rusteron_archive::*;
let context = AeronContext::new()?;
let aeron = Aeron::new(&context)?;
aeron.start()?;
let archive_context = AeronArchiveContext::new()?;
let subscription = PersistentSubscriptionBuilder::new_with_aeron(&archive_context, &aeron)?
.recording_id(0)?
.live_channel("aeron:ipc")?
.live_stream_id(1001)?
.replay_channel("aeron:udp?endpoint=localhost:0")?
.replay_stream_id(1002)?
.build()?;
while !subscription.is_live() && !subscription.has_failed() {
subscription.poll_fn(|message, _header| println!("{} bytes", message.len()), 10)?;
}
subscription.close()?;Implementations§
Source§impl PersistentSubscriptionBuilder
impl PersistentSubscriptionBuilder
Sourcepub fn new() -> Result<Self, AeronCError>
pub fn new() -> Result<Self, AeronCError>
Create a new builder with a default context.
Sourcepub fn new_with_aeron(
archive_context: &AeronArchiveContext,
aeron: &Aeron,
) -> Result<Self, AeronCError>
pub fn new_with_aeron( archive_context: &AeronArchiveContext, aeron: &Aeron, ) -> Result<Self, AeronCError>
A builder whose subscription and archive_context both use aeron, which it sets on
the context too, so neither is left pointing at another client. The built
subscription keeps both open until it closes.
§Errors
Returns the Aeron error if the context cannot be created or either setter fails.
Sourcepub fn aeron(self, aeron: &Aeron) -> Result<Self, AeronCError>
pub fn aeron(self, aeron: &Aeron) -> Result<Self, AeronCError>
Sourcepub fn archive_context(
self,
ctx: &AeronArchiveContext,
) -> Result<Self, AeronCError>
pub fn archive_context( self, ctx: &AeronArchiveContext, ) -> Result<Self, AeronCError>
Set the archive context to use.
§Errors
Returns the Aeron error if the context rejects the archive context.
Sourcepub fn live_channel(self, channel: &str) -> Result<Self, AeronCError>
pub fn live_channel(self, channel: &str) -> Result<Self, AeronCError>
Set the live channel (accepts &str, handles CString conversion internally).
Sourcepub fn live_stream_id(self, id: i32) -> Result<Self, AeronCError>
pub fn live_stream_id(self, id: i32) -> Result<Self, AeronCError>
Set the live stream ID.
Sourcepub fn replay_channel(self, channel: &str) -> Result<Self, AeronCError>
pub fn replay_channel(self, channel: &str) -> Result<Self, AeronCError>
Set the replay channel (accepts &str, handles CString conversion internally).
Sourcepub fn replay_stream_id(self, id: i32) -> Result<Self, AeronCError>
pub fn replay_stream_id(self, id: i32) -> Result<Self, AeronCError>
Set the replay stream ID.
Sourcepub fn start_position(self, pos: i64) -> Result<Self, AeronCError>
pub fn start_position(self, pos: i64) -> Result<Self, AeronCError>
Set the start position.
Sourcepub fn start_from_beginning(self) -> Result<Self, AeronCError>
pub fn start_from_beginning(self) -> Result<Self, AeronCError>
Replay from the beginning of the recording (Aeron FROM_START).
Sourcepub fn start_from_live(self) -> Result<Self, AeronCError>
pub fn start_from_live(self) -> Result<Self, AeronCError>
Skip replay and join the live stream immediately (Aeron FROM_LIVE).
Sourcepub fn recording_id(self, id: i64) -> Result<Self, AeronCError>
pub fn recording_id(self, id: i64) -> Result<Self, AeronCError>
Set the recording ID.
Sourcepub fn listener<L: PersistentSubscriptionListener>(
self,
listener: L,
) -> Result<Self, AeronCError>
pub fn listener<L: PersistentSubscriptionListener>( self, listener: L, ) -> Result<Self, AeronCError>
Set the listener for events.
Sourcepub fn state_counter(self, counter: &AeronCounter) -> Result<Self, AeronCError>
pub fn state_counter(self, counter: &AeronCounter) -> Result<Self, AeronCError>
Pre-allocate the state counter so an external observer can read the PS state-machine
state. If unset the PS allocates one itself. Maps to Aeron’s Context.stateCounter.
The subscription takes the counter over: it closes it, as does setting the slot again.
Keep the counter’s client open until then.
Sourcepub fn join_difference_counter(
self,
counter: &AeronCounter,
) -> Result<Self, AeronCError>
pub fn join_difference_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>
Counter holding the byte gap between replay and live when the live image is added.
Maps to Aeron’s Context.joinDifferenceCounter. Taken over as in Self::state_counter.
Sourcepub fn live_left_counter(
self,
counter: &AeronCounter,
) -> Result<Self, AeronCError>
pub fn live_left_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>
Counter holding the number of times the PS has dropped off the live stream.
Maps to Aeron’s Context.liveLeftCounter. Taken over as in Self::state_counter.
Sourcepub fn live_joined_counter(
self,
counter: &AeronCounter,
) -> Result<Self, AeronCError>
pub fn live_joined_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>
Counter holding the number of times the PS has switched to the live stream.
Maps to Aeron’s Context.liveJoinedCounter. Taken over as in Self::state_counter.
Sourcepub fn build(self) -> Result<AeronArchivePersistentSubscription, AeronCError>
pub fn build(self) -> Result<AeronArchivePersistentSubscription, AeronCError>
Build the persistent subscription, which keeps its Aeron client and archive context open until it closes.