spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
1.01k stars 614 forks source link

Allow Rabbit Streams binding to use Kotlin lambdas #1935

Open sabbyanandan opened 4 years ago

sabbyanandan commented 4 years ago

@mzalewski82 commented on Thu Mar 12 2020

Currently (version 3.0) binding functional support requires java.util.function types. It would be good to allow Kotlin lambdas to be used directly without the need for these types.

Related issue: https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/795

eugenekup commented 3 years ago

Not sure if it worth separate ticket, but when trying to use Kotlin functional binder for GCP pub/sub Spring is logging the is not eligible for getting processed by all BeanPostProcessors message for an Autowired class on a start up (the app still starts).

It is not logging this message when using Consumer interface;

Example with Kotlin lambdas which causes the INFO message:

....
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class TicketSink(@Autowired private val ticketService: TicketService) {

    @Bean
    fun processTicketMsg(): (Ticket) -> Unit = { ticketService.saveTicket(it) }
}

This way there are many messages including the TicketService

INFO 21704 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'ticketService' of type 
[service.TicketService] is not eligible for getting processed by all BeanPostProcessors 
(for example: not eligible for auto-proxying)

All the other classes that are dependencies in the TicketService are also logged with the same message

Example with Consumer interface where there is no TicketService related messages:

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.util.function.Consumer

@Configuration
class TicketSink(@Autowired private val ticketService: TicketService) {

    @Bean
    fun processTicketMsg() = Consumer<Ticket> { ticketService.saveTicket(it) }
}

This way there is a set of the messages that mention some internal classes only, like

Bean 'org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration' of type 
[org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration] is not eligible for getting processed by all 
BeanPostProcessors (for example: not eligible for auto-proxying)