Spring Cloud Stream - interfaces for Producing and Consuming Messages

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:

  1. Supplier<T>
  2. Consumer<T>
  3. 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)

https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_producing_and_consuming_messages

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.

  1. Sink: This is used for marking a service that receives messages from the inbound channel.
  2. Source: This is used for sending messages to the outbound channel.
  3. 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.

Reading material

  1. https://stackoverflow.com/questions/65441549/enablebinding-is-deprecated-in-spring-cloud-stream-3-x
  2. https://medium.com/geekculture/spring-cloud-streams-with-functional-programming-model-93d49696584c

Links to this note