Search code examples
springamazon-web-servicesspring-cloudamazon-kinesisspring-cloud-stream

AWS kinesis consumer with Java and Spring


I want to write an AWS kinesis stream consumer in a Spring boot application. And I'm not sure if Spring has a native support of kinesis, or I have to use the kinesis client library.

According to this blog post org.springframework.integration:spring-integration-aws has it (RELEASE is available in maven repo). However, this example on GitHub uses org.springframework.cloud:spring-cloud-starter-stream-kinesis, which is available only on Spring snapshots repo under 1.0.0.BUILD-SNAPSHOT.

EDIT: The question is, where can I find an example of KinesisMessageDrivenChannelAdapter?


Solution

  • Not clear what is the question though.

    If you are looking for a sample, there is indeed no one. Right the solution we have in Spring is definitely a Channel Adapter for Spring Integration. And that KinesisMessageDrivenChannelAdapter is exactly consumer implementation for AWS Kinesis:

    @SpringBootApplication
    public static class MyConfiguration {
    
        @Bean
        public KinesisMessageDrivenChannelAdapter kinesisInboundChannelChannel(AmazonKinesis amazonKinesis) {
            KinesisMessageDrivenChannelAdapter adapter =
                new KinesisMessageDrivenChannelAdapter(amazonKinesis, "MY_STREAM");
            adapter.setOutputChannel(kinesisReceiveChannel());
            return adapter;
        }
    }
    

    The sample you found on GitHub is for Spring Cloud Stream and based on the Kinesis Binder which indeed is still under development.