-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
GH-2226: Add RetryTopicConfigurationSupport #2227
Changes from all commits
3da9ea9
06979ef
f10f276
58bfaea
c82fa57
39d6549
a887fba
d0f7265
38a58a9
c43f159
dd512b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2022 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.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.kafka.config.RetryTopicConfigurationSupport; | ||
|
||
/** | ||
* Enables the non-blocking topic-based delayed retries feature. To be used in | ||
* {@link Configuration Configuration} classes as follows: | ||
* <pre class="code"> | ||
* | ||
* @EnableKafkaRetryTopic | ||
* @Configuration | ||
* public class AppConfig { | ||
* } | ||
* | ||
* @Component | ||
* public class MyListener { | ||
* | ||
* @RetryableTopic(fixedDelayTopicStrategy = FixedDelayStrategy.SINGLE_TOPIC, backoff = @Backoff(4000)) | ||
* @KafkaListener(topics = "myTopic") | ||
* public void listen(String message, @Header(KafkaHeaders.RECEIVED_TOPIC) String receivedTopic) { | ||
* logger.info("Message {} received in topic {} ", message, receivedTopic); | ||
* } | ||
* | ||
* @DltHandler | ||
* public void dltHandler(Object message, @Header(KafkaHeaders.RECEIVED_TOPIC) String receivedTopic) { | ||
* logger.info("Message {} received in dlt handler at topic {} ", message, receivedTopic); | ||
* } | ||
* </pre> | ||
* | ||
* To configure the feature's components, extend the {@link RetryTopicConfigurationSupport} | ||
* class and override the appropriate methods. Then import the subclass using the | ||
* {@link Import @Import} annotation on a {@link Configuration @Configuration} class, | ||
* such as: | ||
* | ||
* <pre class="code"> | ||
* | ||
* @Configuration | ||
* @EnableKafka | ||
* public class AppConfig extends RetryTopicConfigurationSupport { | ||
* @Override | ||
* protected void configureBlockingRetries(BlockingRetriesConfigurer blockingRetries) { | ||
* blockingRetries | ||
* .retryOn(ShouldRetryOnlyBlockingException.class, ShouldRetryViaBothException.class) | ||
* .backOff(new FixedBackOff(50, 3)); | ||
* } | ||
* | ||
* @Override | ||
* protected void configureNonBlockingRetries(NonBlockingRetriesConfigurer nonBlockingRetries) { | ||
* nonBlockingRetries | ||
* .addToFatalExceptions(ShouldSkipBothRetriesException.class); | ||
* } | ||
* </pre> | ||
* | ||
* @author Tomaz Fernandes | ||
* @since 2.9 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Documented | ||
@Import(RetryTopicConfigurationSupport.class) | ||
@EnableKafka | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this has to be there. Or at least it has to be documented properly: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Now I'm thinking that since Boot's auto configuration already provides an I think that, considering this is a temporary solution until we add this as default in 3.0, maybe it'd be simpler to stick with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, there is no harm: the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if we're introducing a new annotation then, and probably 99% of the users will be using it in a But no worries, I'll keep it as is and we can revise this down the road if needed. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just as a thought, of course we can look into this later, but what if for 3.0 we added this class to This way we'd keep the automatic feature enabling users currently have, while not encumbering other users with this if they don't use it. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, that's not how other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, makes sense. As you said in another post, eventually it'll be a good thing to better integrate this with Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still want to see some mentioning of this meta-annotation in the Javadocs of this |
||
public @interface EnableKafkaRetryTopic { | ||
} |
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.
That's not good say like this: brings an impression that we must not use an
@EnableKafka
anymore.And you even didn't introduce what is
@EnableKafkaRetryTopic
. The side effect with the@EnableKafka
could be explained in the end of this paragraph. Probably in the simple "NOTE: When@EnableKafkaRetryTopic
is used, the@EnableKafka
can be omitted: the former is meta-annotated with the second."