go_zoom_kinesis::processor

Struct KinesisProcessor

source
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,

source

pub fn new( config: ProcessorConfig, processor: P, client: C, store: S, ) -> (Self, Option<Receiver<ProcessingEvent>>)

Creates a new processor instance

§Arguments
  • config - Processor configuration
  • processor - Record processor implementation
  • client - AWS Kinesis client
  • store - Checkpoint storage implementation
§Returns

Returns a tuple of the processor instance and an optional monitoring channel receiver

source

pub async fn run(&self, shutdown_rx: Receiver<bool>) -> Result<()>

Starts processing the Kinesis stream

§Arguments
  • shutdown - Channel receiver for shutdown signals
§Returns

Returns Ok(()) on successful shutdown, or Error on processing failures

source

async fn process_stream(&self, shutdown_rx: &mut Receiver<bool>) -> Result<()>

Process all shards in the stream

source

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 context
  • shard_id - ID of the shard being processed
  • iterator - Shard iterator for getting records
  • shutdown_rx - Channel receiver for shutdown signals
source

async fn initialize_checkpoint( ctx: &ProcessingContext<P, C, S>, shard_id: &str, ) -> Result<Option<String>>

Initialize checkpoint for a shard

§Arguments
  • ctx - Processing context
  • shard_id - ID of the shard to initialize
source

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 context
  • shard_id - ID of the shard
  • checkpoint - Optional checkpoint to start from
  • shutdown_rx - Channel receiver for shutdown signals
source

async fn process_batch( &self, shard_id: &str, iterator: &str, state: &mut ShardProcessingState, shutdown_rx: Receiver<bool>, ) -> Result<BatchResult>

Process a batch of records

source

async fn process_shard( &self, shard_id: &str, shutdown_rx: Receiver<bool>, ) -> Result<()>

Process a single shard

§Arguments
  • ctx - Processing context
  • shard_id - ID of the shard to process
  • shutdown_rx - Channel receiver for shutdown signals
source

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> 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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