Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-Kafka vs. Spring-Cloud-Stream (Kafka)

Using Kafka as a messaging system in a microservice architecture what are the benefits of using spring-kafka vs. spring-cloud-stream + spring-cloud-starter-stream-kafka ?

The spring cloud stream framework supports more messaging systems and has therefore a more modular design. But what about the functionality ? Is there a gap between the functionality of spring-kafka and spring-cloud-stream + spring-cloud-starter-stream-kafka ? Which API is better designed?

Looking forward to read about your opinions

like image 371
Eike Behrends Avatar asked Nov 15 '17 16:11

Eike Behrends


People also ask

What is the difference between Kafka and Kafka stream?

Every topic in Kafka is split into one or more partitions. Kafka partitions data for storing, transporting, and replicating it. Kafka Streams partitions data for processing it. In both cases, this partitioning enables elasticity, scalability, high performance, and fault tolerance.

What is Spring cloud stream Kafka?

Spring Cloud Stream is a framework designed to support stream processing provided by various messaging systems like Apache Kafka, RabbitMQ, etc. The framework allows you to create processing logic without having to deal with any specific platform.

Is Kafka streams part of Kafka?

The Streams API, available as a Java library that is part of the official Kafka project, is the easiest way to write mission-critical, real-time applications and microservices with all the benefits of Kafka's server-side cluster technology.


2 Answers

Spring Cloud Stream with kafka binder rely on Spring-kafka. So the former has all functionalities supported by later, but the former will be more heavyweight. Below are some points help you make the choice:

  1. If you might change kafka into another message middleware in the future, then Spring Cloud stream should be your choice since it hides implementation details of kafka.
  2. If you want to integrate other message middle with kafka, then you should go for Spring Cloud stream, since its selling point is to make such integration easy.
  3. If you want to enjoy the simplicity and not accept performance overhead, then choose spring-kafka
  4. If you plan to migrate to public cloud service such as AWS Kensis, Azure EventHub, then use spring cloud stream which is part of spring cloud family.
like image 116
Warren Zhu Avatar answered Oct 05 '22 17:10

Warren Zhu


Use Spring Cloud Stream when you are creating a system where one channel is used for input does some processing and sends it to one output channel. In other words it is more of an RPC system to replace say RESTful API calls.

If you plan to do an event sourcing system, use Spring-Kafka where you can publish and subscribe to the same stream. This is something that Spring Cloud Stream does not allow you do do easily as it disallows the following

public interface EventStream {     String STREAM = "event_stream";      @Output(EventStream.STREAM)     MessageChannel publisher();      @Input(EventStream.STREAM)     SubscribableChannel stream(); } 

A few things that Spring Cloud Stream helps you avoid doing are:

  • setting up the serializers and deserializers
like image 31
Archimedes Trajano Avatar answered Oct 05 '22 17:10

Archimedes Trajano