I'm trying to use Spring Cloud Stream with a Kafka binder to consume messages from a topic.
Before I used annotations to create the consumer. Now I have use the functional approach, because the annotation is no more available.
These are the dependecies I used:
implementation("org.springframework.cloud:spring-cloud-stream-binder-kafka:4.0.0")
implementation("org.springframework.cloud:spring-cloud-function-kotlin:4.0.0")
This is the application.yaml
spring:
cloud:
function:
definition: consumeMessage
stream:
kafka:
binder:
brokers: localhost:9092
autoAddPartitions: true
bindings:
consumeMessage-in-0:
destination: message
group: message-group
I tried to use a Bean for the consumer itself, but no messages are revieved:
@Service
class MessageListener() {
@Bean
fun consumeMessage(): Consumer<String> = java.util.function.Consumer { payload ->
println(payload)
}
}
I'm using Spring Boot 3 as project base.
It is no possible to reveive any message via the listener. Does anybody know how to solve the problem?