-
Notifications
You must be signed in to change notification settings - Fork 41.1k
When virtual threads are enabled, auto-configure Kafka listener container factories to use a virtual thread based executor #36396
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
When virtual threads are enabled, we configure the container to use a |
I'm using Spring Boot 3.2.2 @KafkaListener(topics = "my-topic")
public void consume(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION) int partition, @Header(KafkaHeaders.OFFSET) int offset) {
log.info("{}", Thread.currentThread().isVirtual()); // false
consumerService.process(message);
} |
Do you have a small sample application which I could use to reproduce that? |
Due to my company policy, I cannot upload any source code here. I'll do it when I'm home. |
After several tests, I think I found the problem. @Bean
@Primary
public ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "my bootstrap server address");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "my group id");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, 120000);
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 30);
props.put(JsonDeserializer.TRUSTED_PACKAGES, "*");
props.put(SECURITY_PROTOCOL, "SASL_PLAINTEXT");
props.put(SECURITY_MECHANISM, "PLAIN");
props.put(SASL_JAAS_CONFIG, "my sasl configuration");
return new DefaultKafkaConsumerFactory<>(props);
} @Bean
@Primary
public ConcurrentKafkaListenerContainerFactory<String, String> containerFactory(ConsumerFactory<String, String> consumerFactory) {
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
return factory;
} I think this causes the problem. |
You can call |
I'm using Spring Boot 3.2.0.
|
@Moscagus If you have a question about configuring Spring Kafka, please ask on Stack Overflow. If you believe you've found a bug in how Spring Kafka manages its threads, please open a Spring Kafka issue. |
Ok thanks |
Through
containerFactory.getContainerProperties().setListenerTaskExecutor(...)
, the factory can be configured with anAsyncTaskExecutor
. We should see if we can auto-configure this, particularly when virtual threads are enabled as it could then be configured with aVirtualThreadTaskExecutor
.The text was updated successfully, but these errors were encountered: