Skip to content

GH-1210: Add Kotlin suspend functions support #2460

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

Merged
merged 2 commits into from
May 25, 2023

Conversation

artembilan
Copy link
Member

Fixes #1210

Kotlin Coroutines are essentially Future wrapping. Therefore, it is natural to have suspend support on @RabbitListener methods as we do now for CompletableFuture and Mono

  • Introduce some utilities since we cannot reuse existing from Spring Messaging: they are there about Kotlin Coroutines only for reactive handlers
  • Some code clean up in the RabbitListenerAnnotationBeanPostProcessor for the latest Java
  • Add optional dep for kotlinx-coroutines-reactor and document the feature

Fixes spring-projects#1210

Kotlin Coroutines are essentially `Future` wrapping.
Therefore, it is natural to have `suspend` support on `@RabbitListener`
methods as we do now for `CompletableFuture` and `Mono`

* Introduce some utilities since we cannot reuse existing from Spring Messaging:
they are there about Kotlin Coroutines only for reactive handlers
* Some code clean up in the `RabbitListenerAnnotationBeanPostProcessor`
for the latest Java
* Add optional dep for `kotlinx-coroutines-reactor` and document the feature
Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work; thanks!

@@ -56,6 +56,7 @@ ext {
jaywayJsonPathVersion = '2.7.0'
junit4Version = '4.13.2'
junitJupiterVersion = '5.9.2'
kotlinCoroutinesVersion = '1.6.4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this version? I see SI is using 1.7.1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is already to realign with SF 6.1. Not sure if current AMQP version should make a jump to not be compatible with SF 6.0.x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

endpoint.setQueueNames(resolvedQueues.stream()
.map(o -> (String) o)
.collect(Collectors.toList()).toArray(new String[0]));
endpoint.setQueueNames(resolvedQueues.stream().map(o -> (String) o).toArray(String[]::new));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention is new line per ..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but looks a bit awkward as a method argument.
I can bring it back if you wish or introduce a local variable.

@jhoanmanuelms
Copy link

jhoanmanuelms commented Aug 15, 2023

Hi there, quick question, will this feature be supported in version 2.4.14? Thanks!

@garyrussell
Copy link
Contributor

@jhoanmanuelms We can take a look, but can provide no guarantee - it depends on how cleanly the code back ports; there are many changes in 3.0.x that might cause too many conflicts.

Please open a new issue so it's not forgotten.

garyrussell pushed a commit to garyrussell/spring-amqp that referenced this pull request Aug 30, 2023
…projects#2460)

* spring-projectsGH-1210: Add Kotlin suspend functions support

Fixes spring-projects#1210

Kotlin Coroutines are essentially `Future` wrapping.
Therefore, it is natural to have `suspend` support on `@RabbitListener`
methods as we do now for `CompletableFuture` and `Mono`

* Introduce some utilities since we cannot reuse existing from Spring Messaging:
they are there about Kotlin Coroutines only for reactive handlers
* Some code clean up in the `RabbitListenerAnnotationBeanPostProcessor`
for the latest Java
* Add optional dep for `kotlinx-coroutines-reactor` and document the feature

* * Remove unused import
garyrussell pushed a commit to garyrussell/spring-amqp that referenced this pull request Aug 30, 2023
…projects#2460)

* spring-projectsGH-1210: Add Kotlin suspend functions support

Fixes spring-projects#1210

Kotlin Coroutines are essentially `Future` wrapping.
Therefore, it is natural to have `suspend` support on `@RabbitListener`
methods as we do now for `CompletableFuture` and `Mono`

* Introduce some utilities since we cannot reuse existing from Spring Messaging:
they are there about Kotlin Coroutines only for reactive handlers
* Some code clean up in the `RabbitListenerAnnotationBeanPostProcessor`
for the latest Java
* Add optional dep for `kotlinx-coroutines-reactor` and document the feature

* * Remove unused import
@garyrussell
Copy link
Contributor

@jhoanmanuelms Turns out the back port was not too challenging; however, I had to pull in an older version of kotlin coroutines because 2.4.x is used with Boot 2.7.x and the versions need to be aligned.

#2519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Kotlin Coroutine support
3 participants