Closed
Description
The default ThreadPoolTaskScheduler
created in DirectMessageListenerContainer#doInitialize
does not get shut down when the container is destroy()
ed. The scheduler's non-daemon threads prevent the app from shutting down cleanly in that case. This doesn't happen when using (the default) "simple" message listener container:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder()
.properties("spring.rabbitmq.listener.type=direct")
.sources(DemoApplication.class)
.run(args);
context.close();
// process does not exit after calling close because DirectMessageListenerContainer#destroy
// does not call taskScheduler.shutdown() and the scheduler's non-daemon threads keep the process alive
}
@Bean
public ApplicationRunner runner(AmqpTemplate template) {
return args -> template.convertAndSend("myqueue", "foo");
}
@Bean
public Queue myQueue() {
return new Queue("myqueue");
}
@RabbitListener(queues = "myqueue")
public void listen(String in) {
System.out.println(in);
}
}
Expected behavior
The process should stop after calling context.close()
.
Version
3.4.5