-
Notifications
You must be signed in to change notification settings - Fork 1.6k
MessageListenerContainer is started even if autoStartup is false #2297
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
Comments
Please learn how to use GitHub markdown to format code properly.
We could consider adding an option to the registry. |
Thx for the advice ). Is there any need in an option? I mean what if just get rid of the contextRefreshed check in KafkaListenerEndpointRegistry.startIfNecessary? |
It has to be an option, the default behavior is correct. |
I presume you are using |
Yep, can do it this way. But it puts restrictions on how the code is organised, create/start/stop/ is just a bit more natural. |
Resolves spring-projects#2297 Add an option to apply `autoStartup` semantics to late registrations. **cherry-pick to 2.9.x, 2.8.x**
Resolves #2297 Add an option to apply `autoStartup` semantics to late registrations. **cherry-pick to 2.9.x, 2.8.x**
Resolves #2297 Add an option to apply `autoStartup` semantics to late registrations. **cherry-pick to 2.9.x, 2.8.x**
Resolves #2297 Add an option to apply `autoStartup` semantics to late registrations. **cherry-pick to 2.9.x, 2.8.x**
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.8,2
Describe the bug
I have a class like this:
@Autowired
private KafkaListenerEndpointRegistry registry;
@KafkaListener(
id = "#{__listener.id}",
groupId = "#{__listener.groupId}",
topics = "#{__listener.topics}",
properties = {"#{__listener.properties}"},
autoStartup = "false") // autostart is disabled, use listener.start()
Instances of the class are created this way:
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public KafkaMessageListener<?, ?> kafkaListener(String groupId,
String[] topics,
String[] properties) {
return new KafkaMessageListener<>(groupId, topics, properties);
when I create an instance of the KafkaMessageListener it starts up despite the fact that autoStartup is "false". I also tried to set
ConcurrentKafkaListenerContainerFactory.setAutoStartup(false) but without success.
I found that KafkaListenerEndpointRegistry starts my listener in this method:
private void startIfNecessary(MessageListenerContainer listenerContainer) {
if (this.contextRefreshed || listenerContainer.isAutoStartup()) {
listenerContainer.start();
}
}
because KafkaListenerEndpointRegistrar.startImmediately is true when I call appCtx.getBean(...)
I expected that when I create an instance of KafkaMessageListener it must not be started.
The text was updated successfully, but these errors were encountered: