Skip to content

Make RetryTopicConfigurationSupport initialize RetryTopicComponentFactory lazily #2478

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

Closed
jgslima opened this issue Nov 11, 2022 · 1 comment · Fixed by #2480
Closed

Make RetryTopicConfigurationSupport initialize RetryTopicComponentFactory lazily #2478

jgslima opened this issue Nov 11, 2022 · 1 comment · Fixed by #2480

Comments

@jgslima
Copy link
Contributor

jgslima commented Nov 11, 2022

Expected Behavior
In classes that extend RetryTopicConfigurationSupport and override the method createComponentFactory(), it should be possible to return an instance of a RetryTopicComponentFactory which is itself a bean of the spring context.

Current Behavior
Currently, this is not possible, because, in RetryTopicConfigurationSupport, the method createComponentFactory() is called in the declaration of the attribute componentFactory. As so, the class that extends RetryTopicConfigurationSupport has no time to use a reference from the application context to return. It does not even help to make the subclass to receive the bean in the constructor, as the superclass is initialized first.

Context
It has been annoying to find a way to return in the override createComponentFactory() an instance which is, or which depends on, beans of the context.

@garyrussell
Copy link
Contributor

Unfortunately, this is not as simple as just making the call to createComponentFactory() "lazy", because it is needed in 3 other bean definitions.

We could, however, detect the existence of a bean of that type in the application context and use that instead of the field.

In the meantime, the only work around I can see is to override those 3 bean definitions destinationTopicResolver, kafkaConsumerBackoffManager and retryTopicConfigurer.

garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Nov 14, 2022
Resolves spring-projects#2478

Allow users to define a `RetryTopicComponentFactory` bean for use in
infrastructure bean definitions.

Previously, although `createComponentFactory()` can be overridden, it is
called early in the class lifecycle and can't have any dependencies on
Spring beans.

Now, if the application context contains a unique bean of this type, it
is used instead.

**Cannot back port due to breaking API changes; work around for 2.9.x is
to override one or more of `destinationTopicResolver`,
`kafkaConsumerBackoffManager` and/or `retryTopicConfigurer` bean definition
methods.**
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Nov 14, 2022
Resolves spring-projects#2478

Allow users to define a `RetryTopicComponentFactory` bean for use in
infrastructure bean definitions.

Previously, although `createComponentFactory()` can be overridden, it is
called early in the class lifecycle and can't have any dependencies on
Spring beans.

Now, if the application context contains a unique bean of this type, it
is used instead.

**Cannot back port due to breaking API changes; work around for 2.9.x is
to override one or more of `destinationTopicResolver`,
`kafkaConsumerBackoffManager` and/or `retryTopicConfigurer` bean definition
methods.**
artembilan pushed a commit that referenced this issue Nov 14, 2022
Resolves #2478

Allow users to define a `RetryTopicComponentFactory` bean for use in
infrastructure bean definitions.

Previously, although `createComponentFactory()` can be overridden, it is
called early in the class lifecycle and can't have any dependencies on
Spring beans.

Now, if the application context contains a unique bean of this type, it
is used instead.

**Cannot back port due to breaking API changes; work around for 2.9.x is
to override one or more of `destinationTopicResolver`,
`kafkaConsumerBackoffManager` and/or `retryTopicConfigurer` bean definition
methods.**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants