Repository navigation
[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.
eolivelli
left a comment
There was a problem hiding this comment.
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:16Could 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 |
tisonkun
left a comment
There was a problem hiding this comment.
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.
eolivelli
left a comment
There was a problem hiding this comment.
Lgtm
Thanks for double checking
|
/pulsarbot run-failure-checks |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18519 +/- ##
============================================
+ Coverage 47.06% 49.62% +2.55%
+ Complexity 8956 8434 -522
============================================
Files 592 489 -103
Lines 56313 53642 -2671
Branches 5844 5703 -141
============================================
+ Hits 26503 26619 +116
+ Misses 26946 24011 -2935
- Partials 2864 3012 +148
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Motivation
Currently there are many acknowledge methods in
Consumerinterface, including:acknowledgeAsyncacknowledgeacknowledgeCumulativeAsyncacknowledgeCumulativeThe 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
MessageAcknowledgerand 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
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: BewareMyPower#9