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

Conversation

chickenchickenlove
Copy link
Contributor

Background

  • I found that the descriptions and methods related to ackDiscarded behave differently during investigating issue.
    /**
    * Set to true if the {@link #setRecordFilterStrategy(RecordFilterStrategy)} is in use.
    * @param ackDiscarded the ackDiscarded.
    */
    public void setAckDiscarded(boolean ackDiscarded) {
    this.ackDiscarded = ackDiscarded;
    }
  • From java docs, when setRecordFilterStrategy() in use, ackDiscarded should be true. however, ackDiscarded is always false even if some BeanPostProcessor call setRecordFilterStrategy() to use RecordFilter.

Changes

  • create new method useRecordFilterStrategy() to bind setRecordFilterStrategy() and setAckDiscarded() to follow java docs.

@@ -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.

@sobychacko
Copy link
Contributor

@chickenchickenlove, Can you add your name as an author to the classes and update any copyright years?

@@ -326,6 +326,7 @@ public void setReplyTemplate(KafkaTemplate<?, ?> replyTemplate) {
@SuppressWarnings("unchecked")
public void setRecordFilterStrategy(RecordFilterStrategy<? super K, ? super V> recordFilterStrategy) {
this.recordFilterStrategy = (RecordFilterStrategy<K, V>) 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.

Looking deeper, I don't think this fix is correct.
See more further:

	/**
	 * Create an instance with the supplied strategy and delegate listener.
	 * @param delegate the delegate.
	 * @param recordFilterStrategy the filter.
	 * @param ackDiscarded true to ack (commit offset for) discarded messages when the
	 * listener is configured for manual acks.
	 */
	public FilteringMessageListenerAdapter(MessageListener<K, V> delegate,
			RecordFilterStrategy<K, V> recordFilterStrategy, boolean ackDiscarded) {

Therefore it is up to end-user to decide if ackDiscarded or not.

So, what the problem we are trying to fix here, please?

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 see 👍

How about fix the java docs of setAckDiscarded 's Set to true if the {@link #setRecordFilterStrategy(RecordFilterStrategy)} is in use. ?

For example, Set to true if the {@link #setRecordFilterStrategy(RecordFilterStrategy)} is in use and ack discarded messages?

Copy link
Member

Choose a reason for hiding this comment

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

How about:

Set to true if the {@link #setRecordFilterStrategy(RecordFilterStrategy)} should ack discarded messages.

?

Copy link
Contributor Author

@chickenchickenlove chickenchickenlove Apr 23, 2024

Choose a reason for hiding this comment

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

It's more suitable. (sorry i'm not good at english well🥲 ).
may i fix it? or it's okay to close this PR if you think that it is not needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.
Just part of this PR is OK.
Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot 🙇‍♂️
I updated It!

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

This is good to go.
Do we have an opened issue to connect this PR into?

@chickenchickenlove
Copy link
Contributor Author

Thanks for you to review this 🙇‍♂️

Do we have an opened issue to connect this PR into?

No, there is no opened issue! I found it while investigating other issue.

@artembilan artembilan added this to the 3.2.0 milestone Apr 23, 2024
@artembilan artembilan merged commit 96b2791 into spring-projects:main Apr 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants