You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add KinesisMessageDrivenChannelAdapter and all the respective infrastructure
* Add mock tests for `KinesisMessageDrivenChannelAdapter`
* Add integration tests based on the Localstack container between
`KinesisMessageHandler` and `KinesisMessageDrivenChannelAdapter`
* Document `KinesisMessageDrivenChannelAdapter`
* Mention via link the `DynamoDbLockRegistry` and `DynamoDbMetadataStore`.
Therefore, add a section id for the Spring Integration in the `dynamodb.adoc`
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/dynamodb.adoc
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,6 +187,7 @@ Note that `DynamoDbClientCustomizer` beans are applied **after** `AwsSyncClientC
187
187
Since it depends on how you will use DynamoDb integration providing a list of IAM policies would be pointless since least privilege model should be used.
188
188
To check what IAM policies DynamoDb uses and see which ones you should use please check https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/using-identity-based-policies.html[IAM policies]
189
189
190
+
[#spring-integration-support]
190
191
=== Spring Integration Support
191
192
192
193
Starting with version 4.0, Spring Cloud AWS provides https://spring.io/projects/spring-integration[Spring Integration] components for Amazon DynamoDB.
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/kinesis.adoc
+72-1Lines changed: 72 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,8 +43,79 @@ public MessageHandler kinesisMessageHandler(KinesisAsyncClient amazonKinesis,
43
43
}
44
44
----
45
45
46
-
The Kinesis service does not provide a "headers"(attributes) abstraction, so the `KinesisMessageHandler` can be configured with the `OutboundMessageMapper` to embed message headers into the record data alongside the payload.
46
+
The `KinesisMessageDrivenChannelAdapter` is a `MessageProducerSupport` implementation to perform record consumption from the Kinesis stream(s).
47
+
Each shard from the provided streams is managed by an internal state machine to ensure shard records ordering and exclusive shard access from the same consumer group.
48
+
An offset of the records for the consuming shard is stored in the `ConcurrentMetadataStore` via `Checkpointer` abstraction.
49
+
If the `CheckpointMode` of the `KinesisMessageDrivenChannelAdapter` is set to `manual`, then `KinesisHeaders.CHECKPOINTER` is populated to the message this channel adapter produces downstream.
50
+
The check-pointed offset is used to initiate an iterator on the shard after the application restart.
51
+
52
+
The `KinesisMessageDrivenChannelAdapter` can be configured with a distributed `LockRegistry<?>` to managed exclusive access to the shard in the cluster of the application consuming from the Kinesis.
53
+
For example, the xref:dynamodb.adoc#spring-integration-support[`DynamoDbLockRegistry`] can be used to manage distributed locks via DynamoDB.
54
+
In the case of many instances of the same consuming application in cluster, a distributed implementation of the `ConcurrentMetadataStore` is recommended, too, e.g. xref:dynamodb.adoc#spring-integration-support[`DynamoDbMetadataStore`].
55
+
This way, when one instance leaves the cluster, it releases its locks for shards, and another instance can obtain those locks and continue consuming from the shard according to the stored offset in the mentioned shared meta-data store.
56
+
57
+
See also `CheckpointMode` Javadocs and related options on the `KinesisMessageDrivenChannelAdapter` for different checkpoint handling algorithms.
58
+
59
+
The `KinesisShardOffset` abstraction is used to represent an initial shard iterator request for all shards in the provided streams, if there is no specific checkpoint record in the `ConcurrentMetadataStore`.
60
+
Or it can be used as an argument of the overloaded `KinesisMessageDrivenChannelAdapter` to consume from the specific shards.
61
+
The concurrency and checkpoint management remain the same even for an explicit shard configuration.
62
+
63
+
The `KinesisMessageDrivenChannelAdapter` also supports a `batch` mode to produce a message with a payload as a list of just returned by the shard iterator records.
64
+
Each record data can be converted from `byte[]` via `Converter` setting.
65
+
By default, a `DeserializingConverter` is used based on Java serialization specification.
66
+
Which is aligned with the settings of the mentioned above `KinesisMessageHandler`.
67
+
68
+
The Kinesis service does not provide a "headers"(attributes) abstraction, so the `KinesisMessageHandler` and `KinesisMessageDrivenChannelAdapter` can be configured with the `OutboundMessageMapper` and `InboundMessageMapper` to embed (and extract) message headers into/from the record data alongside the payload.
47
69
See `EmbeddedHeadersJsonMessageMapper` implementation for more information.
48
70
71
+
When the shard is closed on the Kinesis service, `KinesisMessageDrivenChannelAdapter` emits a `KinesisShardEndedEvent` into the application context with the key based on the pattern `consumerGroup + ":" + stream + ":" + shardId`.
72
+
Such an event can be useful in any arbitrary application logic where the end of the shard is a crucial indicator, e.g. to perform resharding on the stream.
73
+
74
+
The following Java Configuration demonstrates some `KinesisMessageDrivenChannelAdapter`:
75
+
76
+
[source,java]
77
+
----
78
+
@Bean
79
+
public ConcurrentMetadataStore checkpointStore() {
The Spring Integration dependency in the `spring-cloud-aws-kinesis` module is `optional` to avoid unnecessary artifacts on classpath when Spring Integration is not used.
50
121
For convenience, a dedicated `spring-cloud-aws-starter-integration-kinesis` is provided managing all the required dependencies for Spring Integration support with a classical Amazon Kinesis client.
0 commit comments