Expand description
Amazon Kinesis Data Streams broker for the RustStream
messaging framework, backed by the official aws-sdk-kinesis
client.
A subscription reads every shard of one stream, and a publish is one record on the stream the
outgoing message names. The crate adds what the vendor’s consumer library gives other platforms:
shard discovery across splits and merges, a lease per shard, and per-shard checkpoints in a
LeaseStore. An ack is a checkpoint, one instance reads a shard at a time, and delivery is
at-least-once.
§A service
A handler is an async fn over the decoded record, mounted on a broker inside the application
object, and the attribute writes the main:
use ruststream_kinesis::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
}
#[subscriber(KinesisStream::new("orders"))]
async fn handle(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "accepted");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(KinesisBroker::new(), |b| {
b.include(handle);
})
}cargo run -- run starts it. KinesisBroker::new only records the configuration; the region
and the credentials resolve from the environment when the runtime connects the broker, and the
runtime shuts it down when the service stops.
§Where things are
The guides take a Kinesis service from installation to production, in this order: getting started, consuming a stream, shards, partition keys and ordering, checkpoints and delivery guarantees, retries and dead-letter streams, replay and seeking, several instances, testing and running in production. The architecture pages show how the crate sits between the SDK client and the runtime, and the benchmarks what it costs.
Each topic below links to its component page on the site, which shows it in a service; the item’s own documentation keeps the detail.
§Broker
- KinesisBroker:
KinesisBroker, connected intoConnectedKinesisBroker. - Credentials: the AWS default chain at connect, or a config built elsewhere
through
KinesisBroker::from_config. - Endpoint:
KinesisBroker::endpoint,KinesisBroker::regionandKinesisBroker::test_credentials, for a local stack. - Startup: a subscription opens once every shard it took has a reader.
- Shutdown: a handle used after shutdown reports
KinesisError::NotConnected. - Prelude:
prelude, the one glob a Kinesis service imports. - Errors:
KinesisError.
§Subscriptions
- Subscriptions: a bare stream name reads every shard of the stream.
- KinesisStream:
KinesisStream, one stream with every setting of its subscription. - poll_interval:
KinesisStream::poll_interval, the pause between reads of an idle shard. - create_if_missing:
KinesisStream::create_if_missing, a stream created when it is missing. - KinesisSubscriberExt:
KinesisSubscriberExt, the same settings on the mount chain. - Shards: a lease and a reader per shard, and a split’s children after their parents.
- Batches: a slice handler over
KinesisSubscriberbatches.
§Settlement
- Checkpoint:
KinesisMessage, what an ack, a drop and a requeue do on a shard. - retry_after: a deferred copy of the record back to its stream.
- out_retry: the publisher the retry copies leave through.
- Dead letters:
max_attemptsanddead_letter, the stream a spent record goes to.
§Leases
- LeaseStore:
LeaseStore,LeaseStateandSHARD_END, where shard owners and checkpoints live. - MemoryLeaseStore:
MemoryLeaseStore, the default store for one instance. - DynamoLeaseStore:
DynamoLeaseStore, aDynamoDBtable several instances share (featuredynamodb-lease). - LeaseKey:
LeaseKey, one shard of one stream. - owner_id:
KinesisBroker::owner_id, the name this instance holds its leases under. - legacy_stream:
DynamoLeaseStore::legacy_stream, a lease table an earlier version wrote.
§Context
- KinesisContext:
KinesisContextand its keysPositionandSeekHandle. - KinesisBatchContext:
KinesisBatchContext, a batch handler’s context. - Headers:
SEQUENCE_HEADER,SHARD_HEADERandPARTITION_KEY_HEADERon every delivery. - Envelope: how user headers travel inside a record.
§Positions
- KinesisPosition:
KinesisPosition, a place in the stream. - start_at: opening a subscription at a position on every startup.
- Seek:
KinesisSeekerthrough theSeekHandlekey, moving a running subscription.
§Publishing
- KinesisPublish:
KinesisPublish, the publish policy, and its liveKinesisPublisher. - Keys: the four places that name a record’s partition key.
- partition_key:
KinesisPublishSteps::partition_keyandKinesisPublishOptionskey one record. - KinesisPublishSettings:
KinesisPublishSettings::partition_keykeys every record of a position.
§Tooling
- AsyncAPI: the Kinesis bindings of the generated document (feature
asyncapi): the server, the channels and the messages. - Testing: the in-process Kinesis
TestAppconnects the broker to (featuretesting), and Live runs againstLocalStackor AWS.
§Cargo features
All three are additive and off by default. asyncapi contributes the Kinesis bindings to the
generated document, dynamodb-lease adds DynamoLeaseStore, and testing adds the in-process
mode TestApp::start connects the broker through. The codecs are the core’s: a service enables
json, msgpack or cbor on ruststream.
Modules§
- prelude
- The imports a service on Kinesis writes every time, in one glob.
Structs§
- Connected
Kinesis Broker - The typed witness that
connectsucceeded: holds the live SDK client directly. - Dynamo
Lease Store - A
DynamoDB-backed lease store. - Kinesis
Batch Context - This broker’s batch context: the subscription’s reposition handle, shared by every record of the batch.
- Kinesis
Broker - An Amazon Kinesis Data Streams broker for the
RustStreammessaging framework. - Kinesis
Context - This broker’s per-delivery context: where the record sits in the log, and the handle that repositions the subscription it arrived on.
- Kinesis
Message - A record delivered by a
KinesisSubscriber. - Kinesis
Publish - The publish policy for
KinesisPublisher: pure declaration, constructible anywhere, paired with the connected broker by the runtime afterconnect. - Kinesis
Publish Options - The per-message publish settings of this broker: what one call varies, against what the mount site fixed on the policy.
- Kinesis
Publisher - Publishes records to Kinesis streams; the destination is the stream’s name.
- Kinesis
Seeker - Repositions a
KinesisSubscriberwhile its stream runs; minted bySeekable::seeker. - Kinesis
Stream - A subscription descriptor for one Kinesis stream.
- Kinesis
Subscriber - A subscription to one Kinesis stream; yields
KinesisMessages from every owned shard. - Lease
Key - The name one shard’s lease and checkpoint live under: the stream and the shard id.
- Lease
State - The persisted state of one shard’s lease.
- Memory
Lease Store - In-process lease coordination, correct for a single service instance.
- Position
- The key reading this record’s
KinesisPositionout ofKinesisContext. - Seek
Handle - The key reading the subscription’s
KinesisSeekerout of either context.
Enums§
- Kinesis
Error - Errors returned by the Amazon Kinesis Data Streams broker.
- Kinesis
Position - A position in the stream’s retained log: the whole start vocabulary of this broker,
accepted by
Seeker::seekand by thestart_at(..)clause of#[subscriber(..)].
Constants§
- PARTITION_
KEY_ HEADER - Header carrying the partition key, mapped onto the record’s own partition key.
- SEQUENCE_
HEADER - Header exposing the record’s sequence number; every delivery carries it.
- SHARD_
END - The checkpoint value marking a shard fully consumed; its children may start.
- SHARD_
HEADER - Header exposing the shard a record arrived on; every delivery carries it.
Traits§
- Kinesis
Publish Settings - The Kinesis publish settings, chained on a mount site after the position that named the
policy:
.out_reply(policy),.out_retry(policy)or.out(marker, policy). - Kinesis
Publish Steps - The Kinesis publish steps, on the framework’s publish builder.
- Kinesis
Subscriber Ext - The Kinesis subscription settings, chained on a mount site after the framework’s own.
- Lease
Store - Durable coordination for shard leases and checkpoints.
Type Aliases§
- Lease
Error - The boxed error lease stores report; the crate wraps it with the stream and the shard for diagnostics.