I can connect to kafka by using spring cloud task, why to use spring cloud steam
The answer to this question comes down to the fundamental differences between Spring Cloud Task and Spring Cloud Stream.
Spring Cloud Task is for running an application that is bound to complete (success/fail). In other way to say, it is ephemeral.
Spring Cloud Stream is for long running applications where you would keep your applications up and running as long as there is a stream of data flowing through the data pipeline.
If you have an application that connects to RabbitMQ or Kafka and does some task which is bound to be completed in a specific time frame, then you can choose Spring Cloud Task to run this application.
Example Use case: Process information from the database and push the contents into RabbitMQ/Kafka every time you schedule or launch the application manually.
Whereas, if you have an application that connects to RabbitMQ or Kafka but it continuously produce/consume data to/from RabbitMQ or Kafka then, you would need to run this as Spring Cloud Stream application.
Example use case: Process information from the database as and when there is a new record in it and continuously push them into RabbitMQ/Kafka. In this case, you need to have your application up and running to capture the real time events from the database and hence you would choose Spring Cloud Stream application.
The orchestration tool Spring Cloud Data Flow helps managing both types of applications but you need to choose which one to use based on your use cases.