Skip to content

Provide a configuration property for Kafka's async acks #30776

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private void configureContainer(ContainerProperties container) {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
Listener properties = this.properties.getListener();
map.from(properties::getAckMode).to(container::setAckMode);
map.from(properties::getAsyncAcks).to(container::setAsyncAcks);
map.from(properties::getClientId).to(container::setClientId);
map.from(properties::getAckCount).to(container::setAckCount);
map.from(properties::getAckTime).as(Duration::toMillis).to(container::setAckTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,13 @@ public enum Type {
*/
private AckMode ackMode;

/**
* Support for asynchronous record acknowledgments. Only applies with
* ContainerProperties.AckMode.MANUAL or
* ContainerProperties.AckMode.MANUAL_IMMEDIATE.
*/
private Boolean asyncAcks;

/**
* Prefix for the listener's consumer client.id property.
*/
Expand Down Expand Up @@ -969,6 +976,14 @@ public void setAckMode(AckMode ackMode) {
this.ackMode = ackMode;
}

public Boolean getAsyncAcks() {
return this.asyncAcks;
}

public void setAsyncAcks(Boolean asyncAcks) {
this.asyncAcks = asyncAcks;
}

public String getClientId() {
return this.clientId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,20 @@ void streamsApplicationIdIsNotMandatoryIfEnableKafkaStreamsIsNotSet() {
@SuppressWarnings("unchecked")
@Test
void listenerProperties() {
this.contextRunner.withPropertyValues("spring.kafka.template.default-topic=testTopic",
"spring.kafka.template.transaction-id-prefix=txOverride", "spring.kafka.listener.ack-mode=MANUAL",
"spring.kafka.listener.client-id=client", "spring.kafka.listener.ack-count=123",
"spring.kafka.listener.ack-time=456", "spring.kafka.listener.concurrency=3",
"spring.kafka.listener.poll-timeout=2000", "spring.kafka.listener.no-poll-threshold=2.5",
"spring.kafka.listener.type=batch", "spring.kafka.listener.idle-between-polls=1s",
"spring.kafka.listener.idle-event-interval=1s",
"spring.kafka.listener.idle-partition-event-interval=1s", "spring.kafka.listener.monitor-interval=45",
"spring.kafka.listener.log-container-config=true", "spring.kafka.listener.missing-topics-fatal=true",
"spring.kafka.jaas.enabled=true", "spring.kafka.listener.immediate-stop=true",
"spring.kafka.producer.transaction-id-prefix=foo", "spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.control-flag=REQUISITE", "spring.kafka.jaas.options.useKeyTab=true")
this.contextRunner
.withPropertyValues("spring.kafka.template.default-topic=testTopic",
"spring.kafka.template.transaction-id-prefix=txOverride",
"spring.kafka.listener.ack-mode=MANUAL", "spring.kafka.listener.client-id=client",
"spring.kafka.listener.ack-count=123", "spring.kafka.listener.ack-time=456",
"spring.kafka.listener.concurrency=3", "spring.kafka.listener.poll-timeout=2000",
"spring.kafka.listener.no-poll-threshold=2.5", "spring.kafka.listener.type=batch",
"spring.kafka.listener.idle-between-polls=1s", "spring.kafka.listener.idle-event-interval=1s",
"spring.kafka.listener.idle-partition-event-interval=1s",
"spring.kafka.listener.monitor-interval=45", "spring.kafka.listener.log-container-config=true",
"spring.kafka.listener.missing-topics-fatal=true", "spring.kafka.jaas.enabled=true",
"spring.kafka.listener.immediate-stop=true", "spring.kafka.producer.transaction-id-prefix=foo",
"spring.kafka.jaas.login-module=foo", "spring.kafka.jaas.control-flag=REQUISITE",
"spring.kafka.jaas.options.useKeyTab=true", "spring.kafka.listener.async-acks=true")
.run((context) -> {
DefaultKafkaProducerFactory<?, ?> producerFactory = context
.getBean(DefaultKafkaProducerFactory.class);
Expand All @@ -477,6 +479,7 @@ void listenerProperties() {
assertThat(kafkaListenerContainerFactory.getConsumerFactory()).isEqualTo(consumerFactory);
ContainerProperties containerProperties = kafkaListenerContainerFactory.getContainerProperties();
assertThat(containerProperties.getAckMode()).isEqualTo(AckMode.MANUAL);
assertThat(containerProperties.isAsyncAcks()).isEqualTo(true);
assertThat(containerProperties.getClientId()).isEqualTo("client");
assertThat(containerProperties.getAckCount()).isEqualTo(123);
assertThat(containerProperties.getAckTime()).isEqualTo(456L);
Expand Down