Add property to set changeConsumerThreadName for Kafka

Closes gh-36343
This commit is contained in:
Moritz Halbritter
2023-07-26 13:45:10 +02:00
parent 49ae8c0998
commit 9cb5763794
3 changed files with 26 additions and 1 deletions

View File

@@ -199,6 +199,7 @@ public class ConcurrentKafkaListenerContainerFactoryConfigurer {
map.from(this.recordInterceptor).to(factory::setRecordInterceptor);
map.from(this.batchInterceptor).to(factory::setBatchInterceptor);
map.from(this.threadNameSupplier).to(factory::setThreadNameSupplier);
map.from(properties::getChangeConsumerThreadName).to(factory::setChangeConsumerThreadName);
}
private void configureContainer(ContainerProperties container) {

View File

@@ -1043,6 +1043,12 @@ public class KafkaProperties {
*/
private boolean autoStartup = true;
/**
* Whether to instruct the container to change the consumer thread name during
* initialization.
*/
private Boolean changeConsumerThreadName;
public Type getType() {
return this.type;
}
@@ -1179,6 +1185,14 @@ public class KafkaProperties {
this.autoStartup = autoStartup;
}
public Boolean getChangeConsumerThreadName() {
return this.changeConsumerThreadName;
}
public void setChangeConsumerThreadName(Boolean changeConsumerThreadName) {
this.changeConsumerThreadName = changeConsumerThreadName;
}
}
public static class Ssl {

View File

@@ -42,11 +42,14 @@ class ConcurrentKafkaListenerContainerFactoryConfigurerTests {
private ConsumerFactory<Object, Object> consumerFactory;
private KafkaProperties properties;
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
this.configurer = new ConcurrentKafkaListenerContainerFactoryConfigurer();
this.configurer.setKafkaProperties(new KafkaProperties());
this.properties = new KafkaProperties();
this.configurer.setKafkaProperties(this.properties);
this.factory = spy(new ConcurrentKafkaListenerContainerFactory<>());
this.consumerFactory = mock(ConsumerFactory.class);
@@ -60,4 +63,11 @@ class ConcurrentKafkaListenerContainerFactoryConfigurerTests {
then(this.factory).should().setThreadNameSupplier(function);
}
@Test
void shouldApplyChangeConsumerThreadName() {
this.properties.getListener().setChangeConsumerThreadName(true);
this.configurer.configure(this.factory, this.consumerFactory);
then(this.factory).should().setChangeConsumerThreadName(true);
}
}