Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coroutines support for @EventListener #28343

Closed
rotilho opened this issue Apr 14, 2022 · 7 comments
Closed

Add Coroutines support for @EventListener #28343

rotilho opened this issue Apr 14, 2022 · 7 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Milestone

Comments

@rotilho
Copy link
Contributor

rotilho commented Apr 14, 2022

Affects: Any


Spring introduced first-class support to kotlin and coroutines and while almost everything works flawlessly I really miss the support for coroutines in the @EventListener.

I used in the past spring-kotlin-coroutine however this project is not updated for 3 years so I wonder if such support could be added to core Spring.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 14, 2022
@poutsma poutsma added the theme: kotlin An issue related to Kotlin support label Apr 19, 2022
@martinformi
Copy link

It would be really helpful, do you have any working implementation that could replace it for now?

@hantsy
Copy link
Contributor

hantsy commented Aug 26, 2022

The original Spring Kotlin Corutines has great Kotlin Coroutines support, unfortunately it is discontinued. A lot of features are not support in current Spring framework although Spring has supported Kotlin for years.

I used Kotlin Coroutines/Spring Boot in my project, and I found there are still some problems when using Coroutines in events, cache, schedule/async and Spring Security DSL config. I had to wrap the corourtines codes with a runBlocking to use it in the existing facilities of Spring.

@sdeleuze
Copy link
Contributor

Spring supports Coroutines where it support reactive types, and since #21831 supports that use case, we should indeed support this use case.

@sdeleuze sdeleuze removed the theme: kotlin An issue related to Kotlin support label Aug 26, 2022
@sdeleuze sdeleuze added this to the 6.x Backlog milestone Aug 26, 2022
@sdeleuze sdeleuze self-assigned this Aug 26, 2022
@sdeleuze sdeleuze added type: enhancement A general enhancement theme: kotlin An issue related to Kotlin support in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 26, 2022
@hantsy
Copy link
Contributor

hantsy commented Nov 19, 2022

@sdeleuze I would like get the following cases working in a Spring/Kotlin Coroutines project.

  1. Allow a suspend main fun for the application entry.
  2. Coroutines version of ApplicationEventListener, @EventListener on a suspend fun or a fun returns a Kotlin Flow.
  3. Make cache annotations work on any suspend fun or Flow return type.
  4. Make it work in Spring Security Kotlin DSL http{}(similar to route, there is coRoute for coroutines)
  5. provides a coroutines versions of CommandLineRunner, ApplicationRunner, ReactiveAuditorAware, ReactiveEntityCallback, etc.

@sdeleuze
Copy link
Contributor

From my point of view, Spring should not support suspend everywhere, but I fully understand it is not always easy to draw the line between what should be supported and what should not. Notice that this question is not specific to Kotlin Coroutines, but is also true for our Reactive support.

Spring should provides Coroutines support where Reactive types are supported. For example, we recently added support for Reactive/Coroutines to @Scheduled (see #29924).

For event listeners, we indeed support Reactive types on event listeners so it would make sense to support Coroutines as well (see #27515 related issue even if more focused on transactional support).

So let's try to make that happen early in 6.1.x release cycle (tentatively planned for RC2 but that may be postponed depending on my bandwidth).

@sdeleuze sdeleuze modified the milestones: 6.x Backlog, 6.1.0-RC2 Oct 11, 2023
@hantsy
Copy link
Contributor

hantsy commented Oct 11, 2023

Great to see schedule, cache, event listener to get Reactive/Coroutines support in Spring 6.1.

@rotilho
Copy link
Contributor Author

rotilho commented Oct 11, 2023

@sdeleuze awesome work! Super thanks!

@sbrannen sbrannen changed the title @EventListener + Coroutines @EventListener and Coroutines Oct 14, 2023
@sdeleuze sdeleuze changed the title @EventListener and Coroutines Add Coroutines support for @EventListener Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants