A Java Lagom service which only consumes from Kafka topic (Subscriber only service)

Knoldus Blogs

Subscriber only service means an application which only consumes, does not produce.

We have generally seen the applications which both produces and consumes data from a Kafka topic but sometimes we need to write an application which only consumes data i.e. consumes data from a 3rd party service. So in this blog I am going to explain how to write a Lagom service which only consumes data (does not produce any data).

Add below dependency to your impl pom.xml:

We need to create a separate module kafka-connect in Lagom project. That module will contain a Service Descriptor declaring the topic service will consume from.

Then, add kafka-connect dependency in impl module:

Then, to consume data implement consumer as below:

Finally, you need to bind KafkaConsumer as Eager singleton and KafkaService in HelloModule:

To connect with external kafka, made below changes in root pom:

and, add below configuration in application.conf file:

That’s it. Now…

View original post 52 more words


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s