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

Add hasResponded check to Message #84

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add hasResponded check to Message #84

wants to merge 3 commits into from

Conversation

ravisanwal
Copy link

This adds the capability to check if a message has been responded to, by finish or requeue. It also makes these operations idempotent and NOOP after the first attempt.

In addition to this, it also makes touch a NOOP when a message has already been responded to.

Callers can now unconditinally finish or requeue without being concerned about any acknowledgemnt that has happened before. Or they can simply check if a message has been responded to or not.

For backwards-compatility, the interface method defaults to returning false.

This adds the capability to check if a message has been responded to, by `finish` or `requeue`.
It also makes these operations idempotent and NOOP after the first attempt.

In addition to this, it also makes `touch` a NOOP when a message has already been responded to.

Callers can now unconditinally `finish` or `requeue` without being concerned about any acknowledgemnt that has happened before.
Or they can simply check if a message has been responded to or not.

For backwards-compatility, the interface method defaults to returning `false`.
@@ -22,4 +22,8 @@ public interface Message {

void forceFlush();

default boolean hasResponded() {
return false;

Choose a reason for hiding this comment

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

I don't think I like a default for this.

@@ -10,6 +11,7 @@ class NSQMessage implements Message {
private final byte[] data;
private final String topic;
private final SubConnection connection;
private final AtomicBoolean responded = new AtomicBoolean();

Choose a reason for hiding this comment

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

I wonder if we want more granular information about the final state of the message like was it finished, requeued, etc.

Copy link
Author

Choose a reason for hiding this comment

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

@chrisparrinello this is mostly for bringing our library at-par (with respect to this feature) with other ones (go/python)
Adding more granular status, while may be desirable, is a bit out of scope.

blakesmith
blakesmith previously approved these changes Sep 11, 2024
Copy link
Contributor

@blakesmith blakesmith left a comment

Choose a reason for hiding this comment

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

Looks good to me. Extra semicolon nit, but I think this works.

}

@Override
public void requeue(int delayMillis) {
connection.requeue(id, delayMillis);
if (responded.compareAndSet(false, true)) {
connection.requeue(id, delayMillis);;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Extra semicolon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants