2. Spring Cloud Stream
Spring Cloud Stream is a lightweight message-driven microservices framework
based on Spring Integration and Spring Boot, providing the opinionated runtime
for easy configuration.
It provides a simple declarative model for sending and receiving messages using
RabbitMQ ,Apache Kafka or Amazon Kinesis.
SCS decouples the messaging between producers and consumers, by creating
bindings that can be used out of the box. In other words,we need not add broker-
specific code to your application for producing or consuming messages. We just
add the required binding dependencies to the application and Spring Cloud
Stream will take care of the messaging connectivity and communication
3. Spring Cloud Stream Programming Model
● Spring Cloud Stream uses channels (input/output) as a mechanism to send
and receive messages. A Spring Cloud Stream application can have any
number of channels, and it defines two annotations: @Input on
SubscribableChannel class for incoming messages and @Output on
MessageChannel class for sending outgoing messages. These classes
comes from Spring Integration.
● Instead of using these channels directly , SCS has added three interfaces
which is much simplified and covers most common messaging use cases
- Source , Processor and SInk
4. Spring Cloud Stream Programming Model
SCS interfaces involved in publishing and consuming the message
● Source
● Processor
● Sink
5. Spring Cloud Stream Concepts
● Source
A source is a Spring annotated interface that takes a Plain Old Java Object
(POJO) that represents the message to be published. A source takes the
message, serializes it (the default serialization is JSON), and publishes the
message to a channel. A source is used in an application where you are
ingesting data from an external system (by listening into a queue, a REST
call, file system,database query, etc.) and sending it through an output
channel.
6. Spring Cloud Stream Concepts
● Processor
Processor is a Spring annotated interface used in an application when you
want to start listening from the input channel for new incoming messages,
process the message received (enhancements, transformations, etc.), and
send a new message to the output channel.
7. Spring Cloud Stream Concepts
● Sink
A sink listens to a channel for incoming messages and de-serializes the
message back into a plain old Java object. From there, the message can be
processed by the business logic of the service or end the flow (saving data,
firing a task, logging into the console, etc.).