Skip to content

GH-615: Docs - Migrating Legacy Error Handlers #2145

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 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion spring-kafka-docs/src/main/asciidoc/kafka.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5058,6 +5058,8 @@ These error handlers can handle errors for both record and batch listeners, allo
`CommonErrorHandler` implementations to replace most legacy framework error handler implementations are provided and the legacy error handlers deprecated.
The legacy interfaces are still supported by listener containers and listener container factories; they will be deprecated in a future release.

See <<migrating-legacy-eh>> for information to migrate custom error handlers to `CommonErrorHandler`.

When transactions are being used, no error handlers are configured, by default, so that the exception will roll back the transaction.
Error handling for transactional containers are handled by the <<after-rollback,`AfterRollbackProcessor`>>.
If you provide a custom error handler when using transactions, it must throw an exception if you want the transaction rolled back.
Expand Down Expand Up @@ -5267,7 +5269,7 @@ By default, the exception type is not considered.
Also see <<delivery-header>>.

[[batch-listener-conv-errors]]
===== Conversion Errors with Batch Error Handlers
====== Conversion Errors with Batch Error Handlers

Starting with version 2.8, batch listeners can now properly handle conversion errors, when using a `MessageConverter` with a `ByteArrayDeserializer`, a `BytesDeserializer` or a `StringDeserializer`, as well as a `DefaultErrorHandler`.
When a conversion error occurs, the payload is set to null and a deserialization exception is added to the record headers, similar to the `ErrorHandlingDeserializer`.
Expand Down Expand Up @@ -5384,6 +5386,20 @@ If you wish to use a different error handling strategy for record and batch list
|No replacements - use `DefaultErrorHandler` and throw an exception other than `BatchListenerFailedException`.
|===

[[migrating-legacy-eh]]
====== Migrating Custom Legacy Error Handler Implementations to `CommonErrorHandler`

Refer to the javadocs in `CommonErrorHandler`.

To replace an `ErrorHandler` or `ConsumerAwareErrorHandler` implementation, you should implement `handleRecord()` and leave `remainingRecords()` to return `false` (default).
Copy link

@abhaygitty abhaygitty Mar 13, 2023

Choose a reason for hiding this comment

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

The handleRecord() method implementation is deprecated starting from 2.9 and I am using SpringBoot 3.0.2.
Any thoughts on getting around this or an alternative/replacement?|
@garyrussell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the javadocs

* @deprecated in favor of
* {@link #handleOne(Exception, ConsumerRecord, Consumer, MessageListenerContainer)}.

I will fix the docs to reflect that.

You should also implement `handleOtherException()` - to handle exceptions that occur outside the scope of record processing (e.g. consumer errors).

To replace a `RemainingRecordsErrorHandler` implementation, you should implement `handleRemaining()` and override `remainingRecords()` to return `true`.
You should also implement `handleOtherException()` - to handle exceptions that occur outside the scope of record processing (e.g. consumer errors).

To replace any `BatchErrorHandler` implementation, you should implement `handleBatch()`
You should also implement `handleOtherException()` - to handle exceptions that occur outside the scope of record processing (e.g. consumer errors).

[[after-rollback]]
===== After-rollback Processor

Expand Down
4 changes: 2 additions & 2 deletions spring-kafka-docs/src/main/asciidoc/whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ See <<kafka-template-receive>> for more information.
==== `CommonErrorHandler` Added

The legacy `GenericErrorHandler` and its sub-interface hierarchies for record an batch listeners have been replaced by a new single interface `CommonErrorHandler` with implementations corresponding to most legacy implementations of `GenericErrorHandler`.
See <<error-handlers>> for more information.
See <<error-handlers>> and <<migrating-legacy-eh>> for more information.

[[x28-lcc]]
==== Listener Container Changes
Expand Down Expand Up @@ -92,4 +92,4 @@ You can now use blocking and non-blocking retries in conjunction.
See <<retry-topic-combine-blocking>> for more information.

The KafkaBackOffException thrown when using the retryable topics feature is now logged at DEBUG level.
See <<change-kboe-logging-level>> if you need to change the logging level back to WARN or set it to any other level.
See <<change-kboe-logging-level>> if you need to change the logging level back to WARN or set it to any other level.