-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][client] Move acknowledge APIs to another interface and improve docs #18519
[improve][client] Move acknowledge APIs to another interface and improve docs #18519
Conversation
…ove docs ### Motivation Currently there are many acknowledge methods in `Consumer` interface, including: - 7 overloads of `acknowledgeAsync` - 4 overloads of `acknowledge` - 3 overloads of `acknowledgeCumulativeAsync` - 2 overloads of `acknowledgeCumulative` The JavaDocs of these APIs are also massive and duplicated. For example, some terms are not for application users like "pending ack", which should not appear in API Docs. ### Modifications - Add a new interface `MessageAcknowledger` and move the acknowledge APIs into this new interface. - Improve the API docs. For some overload methods, change them to default methods so that duplicated description can be avoided. The new API docs should be much more clear than before. Though this PR adds a new API, the API compatibility is guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it API compatible with applications compiled against the previous version of the API ? is it a binary compatible change ?
There are many components (Functions, Sinks, Sources..) that inherit the Pulsar API from the container, we must ensure that changing the API jars doesn't break compatibility and requires rebuilding the applications
Is there any way to verify it? |
@eolivelli I wrote a function just now with the 2.10.2 dependency. package org.example;
import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;
public class StringLengthExample implements Function<String, Integer> {
@Override
public Integer process(String input, Context context) throws Exception {
return input.length();
}
} <dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-functions-api</artifactId>
<version>2.10.2</version>
</dependency> Then I created the function in the branch of this PR and it works well. ./bin/pulsar-admin functions create \
--jar ./PulsarFunctionDemo-1.0-SNAPSHOT.jar \
--classname org.example.StringLengthExample \
--tenant public \
--namespace default \
--name word-count \
--inputs persistent://public/default/sentences \
--output persistent://public/default/count ./bin/pulsar-client produce sentences -m "hello world java" $ ./bin/pulsar-client consume -s sub count -n 0
...
----- got message -----
key:[null], properties:[__pfn_input_msg_id__=CAsQADAA, __pfn_input_topic__=persistent://public/default/sentences], content:16 Could it verify the API and binary compatibility? |
I added the Consumer related API invocations, it also worked well. final PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
final Consumer<String> consumer = client.newConsumer(Schema.STRING)
.topic("xxx")
.subscriptionName("sub")
.subscribe();
consumer.acknowledge(MessageId.earliest);
consumer.close();
client.close();
return input.length(); The change of this PR is similar to changing the API from public interface A {
void f();
void f(int x);
void g();
} to public interface F {
void f(int x);
// actually the default method is always overrided because the
// previous implementation doesn't make it default
default void f() {
f(0);
}
} public interface A extends F {
void g();
} |
@eolivelli Is there any more concern? If you concerned about the binary compatibility, from https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html, we can see
We can also have a simple verification like:
where
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a good refactor to go. To see the value of separating interfaces, we can actually mock (write test class) against the narrow interface in testing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
Thanks for double checking
/pulsarbot run-failure-checks |
Codecov Report
@@ Coverage Diff @@
## master #18519 +/- ##
============================================
+ Coverage 47.06% 51.15% +4.09%
+ Complexity 8956 7373 -1583
============================================
Files 592 409 -183
Lines 56313 44139 -12174
Branches 5844 4516 -1328
============================================
- Hits 26503 22581 -3922
+ Misses 26946 19109 -7837
+ Partials 2864 2449 -415
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Motivation
Currently there are many acknowledge methods in
Consumer
interface, including:acknowledgeAsync
acknowledge
acknowledgeCumulativeAsync
acknowledgeCumulative
The JavaDocs of these APIs are also massive and duplicated. For example, some terms are not for application users like "pending ack", which should not appear in API Docs.
Modifications
MessageAcknowledger
and move the acknowledge APIs into this new interface.The new API docs should be much more clear than before. Though this PR adds a new API, the API compatibility is guaranteed.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: BewareMyPower#9