Search code examples
apache-kafkajava-streamapache-kafka-streams

Kafka stream vs Kafka Consumer and Java Stream APIs


I am new to Kafka Stream. I wanted to know what benefits one get by using kafka stream APIs instead of using standard kafka Producer / Consumer APIs and doing the stream processing in Consumer with Java Stream APIs.


Solution

  • Java Stream API has nothing to do with Kafka APIs. You can do consumerRecords.forEach from the Consumer poll iterator, or call producer send method from a Java stream as well, and that's about it.

    The Kafka Streams API allows you to more easily map/filter/branch/join topic data, as well as access persistent StateStores. It also has foreach and peek methods, which I assume you're referring to? You have more direct access when to commit your offsets with the Consumer API than any Kafka Streams methods.

    For producer, you cannot use Kafka Streams API to produce original data into a topic.