Spring Cloud Stream - interfaces for Producing and Consuming Messages
Table of Contents
Spring Cloud Functions
https://spring.io/projects/spring-cloud-function
It is a Spring module that promotes implementing business logic in Functional Style
Java functional interfaces:
- Supplier<T>
- Consumer<T>
- Function<T, R>
Functional Interfaces | Kafka |
---|---|
Supplier<OrderEvent> | Send a message to a topic |
Consumer<OrderEvent> | Consume a message from a topic |
Function<OrderEvent, PaymentEvent> | Consume “OrderEvent” and produce “PaymentEvent” |
Deprecated (Do not use)
The annotation-based programming model (@EnableBinding / @StreamListener) has been deprecated in Spring Cloud Stream 3.2.x. Before 3.2.x., to enable connectivity to a message broker for your application, annotate the main class with @EnableBinding
. The @EnableBinding
annotation takes one or more interfaces as parameters.
With spring-cloud-stream 3.x, it is recommended to use functional implementations. Do not use @EnableBinding
.
Spring Cloud Stream provides three interfaces and we can choose between them based on our requirement.
Sink
: This is used for marking a service that receives messages from the inbound channel.Source
: This is used for sending messages to the outbound channel.Processor
: This can be used in case you need both an inbound channel and an outbound channel, as it extends the Source and Sink interfaces.