Class KinesisTemplate
- All Implemented Interfaces:
KinesisOperations
KinesisOperations implementation, sending records through a KinesisAsyncClient.
Synchronous methods delegate to their asynchronous counterparts and unwrap the CompletionException so callers
see the original AWS exception. A batch is split into PutRecords calls of at most 500 records and 5 MiB each,
a conservative size below the current 10 MiB PutRecords limit; the chunks are sent sequentially and their
results merged in request order.
When an ObservationRegistry is set, every send and batch send is recorded as a
KinesisTemplateObservation named spring.aws.kinesis.template. A split batch is still recorded as one
observation carrying the total record and failed counts.
- Since:
- 4.3.0
- Author:
- Matej Nedic
-
Constructor Summary
ConstructorsConstructorDescriptionKinesisTemplate(software.amazon.awssdk.services.kinesis.KinesisAsyncClient kinesisAsyncClient, KinesisMessageConverter messageConverter) Creates a template converting payloads with the given converter.KinesisTemplate(software.amazon.awssdk.services.kinesis.KinesisAsyncClient kinesisAsyncClient, tools.jackson.databind.json.JsonMapper jsonMapper) Creates a template converting payloads with the default converter backed by the givenJsonMapper. -
Method Summary
Modifier and TypeMethodDescriptionsend(SendRequest request) Sends the given record, allowing all record attributes to be set.Sends a record with a random partition key, so it is distributed across the stream's shards.Sends a record with the given partition key, which determines the shard and therefore the ordering group.sendAsync(SendRequest request) Asynchronously sends the given record.Asynchronously sends a record with the given partition key.sendBatch(String streamName, List<SendRequest> requests) Sends any number of records to the same stream, splitting them intoPutRecordscalls of at most 500 records and 5 MiB each, a conservative size below the current 10 MiBPutRecordslimit, and merging the results in request order.sendBatchAsync(String streamName, List<SendRequest> requests) Asynchronously sends any number of records to the same stream, splitting them intoPutRecordscalls of at most 500 records and 5 MiB each, a conservative size below the current 10 MiBPutRecordslimit.voidsetBatchRetryBackOff(@Nullable BackOff batchRetryBackOff) Set aBackOffused to resend batch entries that failed with a retryable error code (ProvisionedThroughputExceededException,InternalFailure).voidsetObservationConvention(KinesisTemplateObservation.Convention observationConvention) Set a customKinesisTemplateObservation.Conventionoverriding the default observation name and key values.voidsetObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Set theObservationRegistrysend operations are observed with.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.awspring.cloud.kinesis.operations.KinesisOperations
send, send, sendAsync, sendAsync
-
Constructor Details
-
KinesisTemplate
public KinesisTemplate(software.amazon.awssdk.services.kinesis.KinesisAsyncClient kinesisAsyncClient, tools.jackson.databind.json.JsonMapper jsonMapper) Creates a template converting payloads with the default converter backed by the givenJsonMapper.- Parameters:
kinesisAsyncClient- the client to send records with.jsonMapper- the mapper used to serialize non-byte[]/Stringpayloads.
-
KinesisTemplate
public KinesisTemplate(software.amazon.awssdk.services.kinesis.KinesisAsyncClient kinesisAsyncClient, KinesisMessageConverter messageConverter) Creates a template converting payloads with the given converter.- Parameters:
kinesisAsyncClient- the client to send records with.messageConverter- the converter used to serialize payloads.
-
-
Method Details
-
setObservationRegistry
public void setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Set theObservationRegistrysend operations are observed with. Defaults toObservationRegistry.NOOP.- Parameters:
observationRegistry- the registry.
-
setObservationConvention
Set a customKinesisTemplateObservation.Conventionoverriding the default observation name and key values.- Parameters:
observationConvention- the convention.
-
setBatchRetryBackOff
Set aBackOffused to resend batch entries that failed with a retryable error code (ProvisionedThroughputExceededException,InternalFailure). The failed entries are resent in a newPutRecordscall after each back-off interval, without blocking a thread, until none remain or the back-off stops; entries with other error codes are never retried. The mergedBatchSendResultreports each record once: successful if any attempt succeeded, otherwise with its last error. Defaults tonull, which disables retrying.Retried records can be written after records that followed them in the batch, so per-shard order is not kept for retried records. The back-off must be bounded.
- Parameters:
batchRetryBackOff- the back-off, ornullto disable retrying.
-
send
Sends a record with a random partition key, so it is distributed across the stream's shards.The partition key is a random UUID.
- Specified by:
sendin interfaceKinesisOperations- Parameters:
streamName- the target stream.payload- the payload to serialize and send.- Returns:
- the sequence number and shard the record was written to.
-
send
Sends a record with the given partition key, which determines the shard and therefore the ordering group.- Specified by:
sendin interfaceKinesisOperations- Parameters:
streamName- the target stream.partitionKey- the partition key.payload- the payload to serialize and send.- Returns:
- the sequence number and shard the record was written to.
-
send
Sends the given record, allowing all record attributes to be set.Blocks on
sendAsync(SendRequest). A failure is rethrown as the original exception, such as the AWS SDK exception, instead of aCompletionException; a checked cause is wrapped in anIllegalStateException.- Specified by:
sendin interfaceKinesisOperations- Parameters:
request- the record to send.- Returns:
- the sequence number and shard the record was written to.
-
sendAsync
public CompletableFuture<SendResult> sendAsync(String streamName, String partitionKey, Object payload) Asynchronously sends a record with the given partition key.- Specified by:
sendAsyncin interfaceKinesisOperations- Parameters:
streamName- the target stream.partitionKey- the partition key.payload- the payload to serialize and send.- Returns:
- a future completing with the sequence number and shard the record was written to.
-
sendAsync
Asynchronously sends the given record.The record is serialized with the configured
KinesisMessageConverterand sent with a singlePutRecordcall, including the request's explicit hash key and sequence number for ordering. Serialization runs on the calling thread, so a conversion failure is thrown by this method rather than returned as a failed future; errors from Kinesis complete the future exceptionally.- Specified by:
sendAsyncin interfaceKinesisOperations- Parameters:
request- the record to send.- Returns:
- a future completing with the sequence number and shard the record was written to.
-
sendBatch
Sends any number of records to the same stream, splitting them intoPutRecordscalls of at most 500 records and 5 MiB each, a conservative size below the current 10 MiBPutRecordslimit, and merging the results in request order. Individual records can fail while a call as a whole succeeds, so the result reports successful and failed records separately.Blocks on
sendBatchAsync(String, List)and rethrows a failure of a wholePutRecordscall as the original exception instead of aCompletionException. Records Kinesis rejects individually do not throw; they are reported inBatchSendResult.failed().- Specified by:
sendBatchin interfaceKinesisOperations- Parameters:
streamName- the target stream, which every request must target.requests- the records to send.- Returns:
- the successful and failed records of the batch, in request order.
-
sendBatchAsync
public CompletableFuture<BatchSendResult> sendBatchAsync(String streamName, List<SendRequest> requests) Asynchronously sends any number of records to the same stream, splitting them intoPutRecordscalls of at most 500 records and 5 MiB each, a conservative size below the current 10 MiBPutRecordslimit.All requests are serialized on the calling thread before the first call, so a conversion failure is thrown by this method and nothing is sent. The chunks are sent one after another, so records of a shard keep their request order unless a
batch retry back-offresends some of them. If aPutRecordscall fails as a whole, the future completes exceptionally and records of earlier chunks may already have been written.SendRequest.sequenceNumberForOrdering()is ignored, becausePutRecordsdoes not support it.- Specified by:
sendBatchAsyncin interfaceKinesisOperations- Parameters:
streamName- the target stream, which every request must target.requests- the records to send.- Returns:
- a future completing with the successful and failed records of the batch, in request order.
-