spring-cloud-stream icon indicating copy to clipboard operation
spring-cloud-stream copied to clipboard

Allow Rabbit Streams binding to use Kotlin lambdas

Open sabbyanandan opened this issue 4 years ago • 1 comments

@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

sabbyanandan avatar Mar 24 '20 15:03 sabbyanandan

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)

eugenekup avatar Jul 14 '21 16:07 eugenekup