Skip to content

MessageListenerContainer is started even if autoStartup is false #2297

Closed
@tbarabanov

Description

@tbarabanov

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions