Skip to content

contextRefreshed in KafkaListenerEndpointRegistry seems useLess #2315

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
youngkangrui opened this issue Jun 22, 2022 · 1 comment
Closed

Comments

@youngkangrui
Copy link

youngkangrui commented Jun 22, 2022

version 2.8.6

Describe the bug
if set autoStartUp = false ,eg @KafkaListener(autoStartUp="false"),i find container do not start up even spring context has started,
but in the code,container starts depending on either contextRereshed or autoStartUp,so i think if context has started, container should start too , even if autoStartUp=false

To Reproduce

public class TestListener {
    @KafkaListener(id="id1",topics = {"tp"},groupId = "consumerGroupId",autoStartup = "false")
    public void Listen(String info){
        System.out.println(info);
    }
}

ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
		KafkaListenerEndpointRegistry registry = (KafkaListenerEndpointRegistry)context.getBean("org.springframework.kafka.config.internalKafkaListenerEndpointRegistry");
		MessageListenerContainer id1 = registry.getListenerContainer("id1");
		System.out.println(id1.isRunning());

Expected behavior
i think if context has started, container should start too , even if autoStartUp=false , otherwise what the use of contextRefreshed in KafkaListenerEndpointRegistry?

@garyrussell
Copy link
Contributor

garyrussell commented Jun 22, 2022

Please learn to use GitHub markdown to format code.

I think you are misunderstanding the concept of autoStartup.

It is only examined during the context refresh; simply getting a singleton bean will not start it; you need to start() it yourself.

If your bean is a prototype, it will be started after the refresh.

In fact, someone complained about the opposite behavior recently, where newly registered containers are started, even if autoStartup is false.

We added a new boolean to the registry for that purpose; #2301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants