Skip to content
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

Fix ackDiscarded. #3212

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -702,12 +702,12 @@ private void resolveContentTypeConverter(MethodKafkaListenerEndpoint<?, ?> endpo
private void resolveFilter(MethodKafkaListenerEndpoint<?, ?> endpoint, KafkaListener kafkaListener) {
Object filter = resolveExpression(kafkaListener.filter());
if (filter instanceof RecordFilterStrategy rfs) {
endpoint.setRecordFilterStrategy(rfs);
endpoint.useRecordFilterStrategy(rfs);
}
else {
String filterBeanName = resolveExpressionAsString(kafkaListener.filter(), "filter");
if (StringUtils.hasText(filterBeanName)) {
endpoint.setRecordFilterStrategy(
endpoint.useRecordFilterStrategy(
this.beanFactory.getBean(filterBeanName, RecordFilterStrategy.class));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -373,7 +373,7 @@ public C createListenerContainer(KafkaListenerEndpoint endpoint) {
private void configureEndpoint(AbstractKafkaListenerEndpoint<K, V> aklEndpoint) {
if (aklEndpoint.getRecordFilterStrategy() == null) {
JavaUtils.INSTANCE
.acceptIfNotNull(this.recordFilterStrategy, aklEndpoint::setRecordFilterStrategy);
.acceptIfNotNull(this.recordFilterStrategy, aklEndpoint::useRecordFilterStrategy);
}
JavaUtils.INSTANCE
.acceptIfNotNull(this.ackDiscarded, aklEndpoint::setAckDiscarded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ public void setAckDiscarded(boolean ackDiscarded) {
this.ackDiscarded = ackDiscarded;
}

public void useRecordFilterStrategy(RecordFilterStrategy<? super K, ? super V> recordFilterStrategy) {
setRecordFilterStrategy(recordFilterStrategy);
setAckDiscarded(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new method does not make too much sense since we simply can do this setAckDiscarded(true) in the existing setRecordFilterStrategy().
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, i made new commit to follow your guideline.
It is good point! 👍

I was just worried that including setAckDiscarded(true) in setFilterStrategy(...) might bring unintended side effects. For example, a developer might not expect that ackDiscarded would change when updating setFilterStrategy(), since it's not specified in the method signature.

}

@Nullable
@Override
public String getClientIdPrefix() {
Expand Down