forked from spring-projects/spring-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support `Mono` and `Future` * Support auto ack at async return scenario when manual commit * Support `KafkaListenerErrorHandler` * Add warn log if the container is not configured for out-of-order manual commit * Add async return test in `BatchMessagingMessageListenerAdapterTests` and `MessagingMessageListenerAdapterTests` * Add unit test async listener with `@SendTo` in `AsyncListenerTests` * Add `async-returns.adoc` and `whats-new.adoc`
- Loading branch information
1 parent
9852ebc
commit 4067cfb
Showing
9 changed files
with
527 additions
and
17 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../src/main/antora/modules/ROOT/pages/kafka/receiving-messages/async-returns.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[[async-returns]] | ||
= Asynchronous `@KafkaListener` Return Types | ||
|
||
`@KafkaListener` (and `@KafkaHandler`) methods can be specified with asynchronous return types `CompletableFuture<?>` and `Mono<?>`, letting the reply be sent asynchronously. | ||
|
||
[source, java] | ||
---- | ||
@KafkaListener(id = "myListener", topics = "myTopic") | ||
public CompletableFuture<String> listen(String data) { | ||
... | ||
CompletableFuture<String> future = new CompletableFuture<>(); | ||
future.complete("done"); | ||
return future; | ||
} | ||
---- | ||
|
||
[source, java] | ||
---- | ||
@KafkaListener(id = "myListener", topics = "myTopic") | ||
public Mono<Void> listen(String data) { | ||
... | ||
return Mono.empty(); | ||
} | ||
---- | ||
|
||
IMPORTANT: The listener container factory must be configured with manual ack mode and async ack to enable out-of-order commits; instead, the asynchronous completion will ack or nack the message when the async operation completes. | ||
When the async result is completed with an error, whether the message is recover or not depends on the container error handler. | ||
If some exception occurs within the listener method that prevents creation of the async result object, you MUST catch that exception and return an appropriate return object that will cause the message to be ack or recover. | ||
|
||
If a `KafkaListenerErrorHandler` is configured on a listener with an async return type, the error handler is invoked after a failure. | ||
See xref:kafka/annotation-error-handling.adoc[Handling Exceptions] for more information about this error handler and its purpose. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.