-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 dltHandlerMethod
field to @RetryableTopic
annotation matching RetryTopicConfigurationBuilder
#3183
Closed
JooHyukKim
wants to merge
3
commits into
spring-projects:main
from
JooHyukKim:Add-matching-dlthandlermethod-in-method
Closed
Add dltHandlerMethod
field to @RetryableTopic
annotation matching RetryTopicConfigurationBuilder
#3183
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
spring-kafka/src/main/java/org/springframework/kafka/annotation/DltHandlerMethod.java
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,59 @@ | ||
/* | ||
* Copyright 2018-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.kafka.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.kafka.support.EndpointHandlerMethod; | ||
|
||
/** | ||
* Annotation to configure the {@link org.springframework.kafka.support.EndpointHandlerMethod} for handling the DLT, | ||
* as part of {@link RetryableTopic} annotation configuration. | ||
* This is equivalent to the builder way of {@link org.springframework.kafka.retrytopic.RetryTopicConfigurer} | ||
* configuration via {@link org.springframework.kafka.retrytopic.RetryTopicConfigurationBuilder#dltHandlerMethod(EndpointHandlerMethod)}. | ||
* | ||
* @author Joo Hyuk Kim | ||
* | ||
* @since 3.2 | ||
* | ||
* @see org.springframework.kafka.retrytopic.RetryTopicConfigurationBuilder#dltHandlerMethod(String, String) | ||
* | ||
*/ | ||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface DltHandlerMethod { | ||
|
||
/** | ||
* The bean name of the DLT handler method. | ||
* | ||
* @return the bean name. | ||
*/ | ||
String beanName() default ""; | ||
|
||
/** | ||
* The method name of the DLT handler method. | ||
* | ||
* @return the method name. | ||
*/ | ||
String methodName() default ""; | ||
|
||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, thanks for looking into this!
I wonder if, according to the annotation-driven model, it would be more natural to have something like this instead:
in the same class where we have that
@RetryableTopic
.See similar model with
@Retryable
and@Recover
in Spring Retry.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it can be subjective as to what natural is 🤔.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into how
@RetryableTopic
is implemented,@RetryableTopic
is really is just annotation-representation ofRetryTopicConfigurationBuilder
which gets constructed using theRetryTopicConfigurationBuilder
itself during startup.This is why it also sort of felt natural (unfortunately 😅) to make current proprosal (PR). We are trying to resolve this asymmetry between the two approaches.
RetryTopicConfiguration
, we only need aRetryTopicConfigurationBuilder
to configure both in one go, builder-style@RetryableTopic
, we are restricted to same-class, same method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But still, maintainer's design perspective also counts alot, so lemme know what you think, @artembilan! ✌🏼✌🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you said before, the
RetryTopicConfiguration
is global. The@RetryableTopic
is for specific service, therefore it feels logical that DLT handler must be that service-specific as well.So, when you encapsulate logic for your
@RetryableTopic
, you definitely might go the way to encapsulate DLT over there as well.Therefore, in most cases, your new annotation would point to the same service and method in there.
Let's just stick with best practice how to design this kind of services!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. yes I said the
RetryTopicConfiguration
is global. At the same time, I also believe that@RetryableTopic
being for specific service is of capability/choice, not as restriction? That much of freedom feels reasonable knowing that DLT can already be configured viaRetryTopicConfigurationBuilder
.And as per encapsulation of DLT, we have
RetryTopicConfigurationBuilder
which already allows configuration of DLT, meaning retry and DLT's can be associated?This PR is not introducing a new dependency between two isolated concepts -between Retry and DLT, but already existing capability of one-go-configuration via
RetryTopicConfiguration
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, again: with an annotation we already have a scope of the method where it is declared, so comparing
RetryTopicConfigurationBuilder
and annotation configuration is not really one-to-one.Therefore, if we go the way of annotation DLT, then I'd prefer to have it in a scope where its
@RetryableTopic
counterpart is declared.Plus we already have a positive experience with the patter we have in Spring Retry.
Or even see here
@KafkaHandler
and itsisDefault()
attribute.Another example is a
@RestController
with its@..Mapping
and@ExceptionHandler
.So, the general point is: if we have a service and give some its method a specific
@KafkaListener
aspect, the other related aspects must be declared in this service as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the insightful explanation🙏🏽🙏🏽
Took me a while to realize the differences between the annotation and builder way, and how it all fits overall design of Spring libraries.
It also makes sense to consider the positive feedback for the current state implementation👍🏼. Thanks again @artembilan!