-
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
Retry-topics auto creation also creates the main topic #2432
Comments
Indeed, as the default behaviour of spring-kafka, when sending the record to the retry or DLT topics, is to assume that the partition in those topics should be the same as the original topic, this means that the retry topics should have the same amount of partitions as the main one (although I think that the default behaviour of However the claim to have a distinct configuration of replication factor should be enough to expect that the framework might have at least some configuration to indicate that, the topics auto-creation feature of the retry mechanism should be done solely for the retry and DLT topics. |
This is a bit of a hack, but it will serve as a work around until we can get this implemented: @SpringBootApplication
public class Kgh2432Application {
public static void main(String[] args) {
SpringApplication.run(Kgh2432Application.class, args);
}
@KafkaListener(id = "kgh2432", topics = "kgh2432")
@RetryableTopic
void listen(String in) {
System.out.println(in);
}
@Bean
NewTopic topic() {
return TopicBuilder.name("kgh2432").partitions(10).replicas(1).build();
}
@Bean
ApplicationRunner runner(KafkaAdmin admin) {
return args -> {
Map<String, TopicDescription> topics = admin.describeTopics("kgh2432", "kgh2432-dlt");
Assert.state(topics.get("kgh2432").partitions().size() == 10, "Wrong main partitions");
Assert.state(topics.get("kgh2432-dlt").partitions().size() == 1, "Wrong DLT partitions");
};
}
}
@Component
class NewTopicWeeder implements SmartInitializingSingleton, Ordered {
private final DefaultListableBeanFactory beanFactory;
NewTopicWeeder (DefaultListableBeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
public int getOrder() {
return 0;
}
@Override
public void afterSingletonsInstantiated() {
this.beanFactory.destroySingleton("kgh2432-topicRegistrationBean");
}
} |
Resolves spring-projects#2432 Don't provision an individual retry topic bean, if there is already a `NewTopic` bean with the same topic name. **cherry-pick to 2.9.x, 2.8.x**
Resolves #2432 Don't provision an individual retry topic bean, if there is already a `NewTopic` bean with the same topic name. **cherry-pick to 2.9.x, 2.8.x** * Fix `TopicForRetry` removal logic; include `NewTopics` beans in logic. * Improve test.
Resolves #2432 Don't provision an individual retry topic bean, if there is already a `NewTopic` bean with the same topic name. **cherry-pick to 2.9.x, 2.8.x** * Fix `TopicForRetry` removal logic; include `NewTopics` beans in logic. * Improve test. # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/core/KafkaAdmin.java # spring-kafka/src/main/java/org/springframework/kafka/retrytopic/RetryTopicConfigurer.java
Resolves #2432 Don't provision an individual retry topic bean, if there is already a `NewTopic` bean with the same topic name. **cherry-pick to 2.9.x, 2.8.x** * Fix `TopicForRetry` removal logic; include `NewTopics` beans in logic. * Improve test. # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/core/KafkaAdmin.java # spring-kafka/src/main/java/org/springframework/kafka/retrytopic/RetryTopicConfigurer.java # Conflicts: # spring-kafka/src/test/java/org/springframework/kafka/retrytopic/RetryTopicIntegrationTests.java
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.9.1
Actually I already saw this behaviour since 2.8, not sure the oldest version that has this behaviour.
Describe the bug
When the
autoCreateTopics
feature of the Non-blocking retries main feature is activated, the framework also creates the main topic with the configurations (partitions and replicas) of the retry topics, even if the context has asNewTopic
bean for the main topic with different configurations.To Reproduce
Run the application below:
Expected behavior
The main topic
"mytopic"
to be created with 10 partitions and 2 replicas, and the retry and DLT topic to be created with 5 partitions and 1 replicas.But actually, the main topic
"mytopic"
is also created with 5 partitions and 1 replica.Sample
See the code above.
The text was updated successfully, but these errors were encountered: