pub struct KinesisProcessor<P, C, S>where
P: RecordProcessor + Send + Sync + 'static,
P::Item: Send + Sync + 'static,
C: KinesisClientTrait + Send + Sync + Clone + 'static,
S: CheckpointStore + Send + Sync + Clone + 'static,{
context: ProcessingContext<P, C, S>,
}
Expand description
Main Kinesis stream processor
Handles the orchestration of:
- Shard discovery and management
- Record batch processing
- Checkpointing
- Monitoring
- Graceful shutdown
§Examples
use go_zoom_kinesis::{KinesisProcessor, ProcessorConfig, RecordProcessor, ProcessorError};
use aws_sdk_kinesis::Client;
use go_zoom_kinesis::store::InMemoryCheckpointStore;
async fn run_processor(
processor: impl RecordProcessor + 'static,
client: Client,
config: ProcessorConfig
) -> Result<(), ProcessorError> {
let store = InMemoryCheckpointStore::new();
let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);
let (processor, _monitoring_rx) = KinesisProcessor::new(
config,
processor,
client,
store
);
processor.run(shutdown_rx).await
}
Fields§
§context: ProcessingContext<P, C, S>
Implementations§
source§impl<P, C, S> KinesisProcessor<P, C, S>where
P: RecordProcessor + Send + Sync + 'static,
C: KinesisClientTrait + Send + Sync + Clone + 'static,
S: CheckpointStore + Send + Sync + Clone + 'static,
impl<P, C, S> KinesisProcessor<P, C, S>where
P: RecordProcessor + Send + Sync + 'static,
C: KinesisClientTrait + Send + Sync + Clone + 'static,
S: CheckpointStore + Send + Sync + Clone + 'static,
sourcepub fn new(
config: ProcessorConfig,
processor: P,
client: C,
store: S,
) -> (Self, Option<Receiver<ProcessingEvent>>)
pub fn new( config: ProcessorConfig, processor: P, client: C, store: S, ) -> (Self, Option<Receiver<ProcessingEvent>>)
sourceasync fn process_stream(&self, shutdown_rx: &mut Receiver<bool>) -> Result<()>
async fn process_stream(&self, shutdown_rx: &mut Receiver<bool>) -> Result<()>
Process all shards in the stream
sourceasync fn get_records_batch(
ctx: &ProcessingContext<P, C, S>,
shard_id: &str,
iterator: &str,
shutdown_rx: &mut Receiver<bool>,
) -> Result<(Vec<Record>, Option<String>)>
async fn get_records_batch( ctx: &ProcessingContext<P, C, S>, shard_id: &str, iterator: &str, shutdown_rx: &mut Receiver<bool>, ) -> Result<(Vec<Record>, Option<String>)>
Get a batch of records from a shard
§Arguments
ctx
- Processing contextshard_id
- ID of the shard being processediterator
- Shard iterator for getting recordsshutdown_rx
- Channel receiver for shutdown signals
sourceasync fn initialize_checkpoint(
ctx: &ProcessingContext<P, C, S>,
shard_id: &str,
) -> Result<Option<String>>
async fn initialize_checkpoint( ctx: &ProcessingContext<P, C, S>, shard_id: &str, ) -> Result<Option<String>>
Initialize checkpoint for a shard
§Arguments
ctx
- Processing contextshard_id
- ID of the shard to initialize
sourceasync fn get_initial_iterator(
ctx: &ProcessingContext<P, C, S>,
shard_id: &str,
checkpoint: &Option<String>,
shutdown_rx: &mut Receiver<bool>,
) -> Result<String>
async fn get_initial_iterator( ctx: &ProcessingContext<P, C, S>, shard_id: &str, checkpoint: &Option<String>, shutdown_rx: &mut Receiver<bool>, ) -> Result<String>
Get initial iterator for a shard
§Arguments
ctx
- Processing contextshard_id
- ID of the shardcheckpoint
- Optional checkpoint to start fromshutdown_rx
- Channel receiver for shutdown signals
sourceasync fn process_batch(
&self,
shard_id: &str,
iterator: &str,
state: &mut ShardProcessingState,
shutdown_rx: Receiver<bool>,
) -> Result<BatchResult>
async fn process_batch( &self, shard_id: &str, iterator: &str, state: &mut ShardProcessingState, shutdown_rx: Receiver<bool>, ) -> Result<BatchResult>
Process a batch of records
sourceasync fn process_shard(
&self,
shard_id: &str,
shutdown_rx: Receiver<bool>,
) -> Result<()>
async fn process_shard( &self, shard_id: &str, shutdown_rx: Receiver<bool>, ) -> Result<()>
Process a single shard
§Arguments
ctx
- Processing contextshard_id
- ID of the shard to processshutdown_rx
- Channel receiver for shutdown signals
sourcefn handle_early_shutdown(shard_id: &str) -> Result<()>
fn handle_early_shutdown(shard_id: &str) -> Result<()>
Handle early shutdown request
Auto Trait Implementations§
impl<P, C, S> Freeze for KinesisProcessor<P, C, S>
impl<P, C, S> RefUnwindSafe for KinesisProcessor<P, C, S>
impl<P, C, S> Send for KinesisProcessor<P, C, S>
impl<P, C, S> Sync for KinesisProcessor<P, C, S>
impl<P, C, S> Unpin for KinesisProcessor<P, C, S>
impl<P, C, S> UnwindSafe for KinesisProcessor<P, C, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.