Skip to content

Async suspend function listener not automatically acknowledged? #3740

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

Closed
artembilan opened this issue Feb 13, 2025 · 1 comment · Fixed by #3742
Closed

Async suspend function listener not automatically acknowledged? #3740

artembilan opened this issue Feb 13, 2025 · 1 comment · Fixed by #3742

Comments

@artembilan
Copy link
Member

Discussed in #3739

Originally posted by rbraeunlich February 13, 2025
Hi everyone,
I was wondering about an error in my application (not part of my question). While trying to simplyfy my code, e.g. by using a suspend function in my listener, which is now being supported, I tried to find out if I have to do the ack by myself. I checked the documentation and also found this earlier question: #3290
This indicates that I don't have to do the ack myself. Nevertheless, when debugging my integration tests I could see that the first message never was acknowledged. When doing it myself, all tests pass.
The critical part seems to be this line:
https://github.com/spring-projects/spring-kafka/blob/main/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java#L553

My suspend function doesn't return anything and therefore the adapter doesn't do the ack for me. The documentation only states "return types include CompletableFuture, Mono and Kotlin suspend functions". Not that my suspend function has to return anything.
Additionally, if I was to return a kotlinx.coroutines.Job or kotlinx.coroutines.Deferred the helper in org.springframework.kafka.listener.adapter.AdapterUtils#isAsyncReply wouldn't recognize them because it only checks for Mono and CompletableFuture.

So, I wonder if the documentation here needs to be more specific or if the code is wrong.

Cheers,
Ronny

@artembilan
Copy link
Member Author

This is a bug after #1189.

artembilan added a commit to artembilan/spring-kafka that referenced this issue Feb 13, 2025
… functions

Fixes: spring-projects#3740
Issue link: spring-projects#3740

Even if Kotlin `suspend` functions are called properly, the acknowledgement is not called
because this kind of method is not treated as an `asyncReplies` mode

* Fix `HandlerAdapter` to check for `KotlinDetector.isSuspendingFunction()`
in addition to `CompletableFuture` & `Mono`
* Adjust `EnableKafkaKotlinCoroutinesTests.kt` to verify that `acknowledgement` has been called
by the Framework

**Auto-cherry-pick to `3.3.x` & `3.2.x`**
artembilan added a commit that referenced this issue Feb 13, 2025
Fixes: #3740
Issue link: #3740

Even if Kotlin `suspend` functions are called properly, the acknowledgement is not called
because this kind of method is not treated as an `asyncReplies` mode

* Fix `HandlerAdapter` to check for `KotlinDetector.isSuspendingFunction()`
in addition to `CompletableFuture` & `Mono`
* Adjust `EnableKafkaKotlinCoroutinesTests.kt` to verify that `acknowledgement` has been called
by the Framework

**Auto-cherry-pick to `3.2.x`**
# Conflicts:
#	spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/HandlerAdapter.java
spring-builds pushed a commit that referenced this issue Feb 13, 2025
Fixes: #3740
Issue link: #3740

Even if Kotlin `suspend` functions are called properly, the acknowledgement is not called
because this kind of method is not treated as an `asyncReplies` mode

* Fix `HandlerAdapter` to check for `KotlinDetector.isSuspendingFunction()`
in addition to `CompletableFuture` & `Mono`
* Adjust `EnableKafkaKotlinCoroutinesTests.kt` to verify that `acknowledgement` has been called
by the Framework

# Conflicts:
#	spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/HandlerAdapter.java

(cherry picked from commit 914cf62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants