Skip to content

Commit 65aa49a

Browse files
committed
[fix][client] Add description method to ClientBuilder (apache#24728)
(cherry picked from commit 65b3541) Signed-off-by: Zixuan Liu <[email protected]>
1 parent 571166e commit 65aa49a

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
import org.apache.pulsar.client.admin.PulsarAdminException;
9797
import org.apache.pulsar.client.api.schema.GenericRecord;
9898
import org.apache.pulsar.client.impl.BatchMessageIdImpl;
99-
import org.apache.pulsar.client.impl.ClientBuilderImpl;
10099
import org.apache.pulsar.client.impl.ConsumerBase;
101100
import org.apache.pulsar.client.impl.ConsumerImpl;
102101
import org.apache.pulsar.client.impl.MessageIdImpl;
@@ -4815,7 +4814,7 @@ public void testClientVersion() throws Exception {
48154814
assertEquals(stats.getPublishers().size(), 1);
48164815
assertEquals(stats.getPublishers().get(0).getClientVersion(), defaultClientVersion);
48174816

4818-
PulsarClient client = ((ClientBuilderImpl) PulsarClient.builder())
4817+
PulsarClient client = PulsarClient.builder()
48194818
.description("my-java-client")
48204819
.serviceUrl(lookupUrl.toString())
48214820
.build();

pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ClientBuilder.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,21 @@ ClientBuilder authentication(String authPluginClassName, Map<String, String> aut
616616
* @return
617617
*/
618618
ClientBuilder socks5ProxyPassword(String socks5ProxyPassword);
619+
620+
/**
621+
* Set the description.
622+
*
623+
* <p> By default, when the client connects to the broker, a version string like "Pulsar-Java-v<x.y.z>" will be
624+
* carried and saved by the broker. The client version string could be queried from the topic stats.
625+
*
626+
* <p> This method provides a way to add more description to a specific PulsarClient instance. If it's configured,
627+
* the description will be appended to the original client version string, with '-' as the separator.
628+
*
629+
* <p>For example, if the client version is 3.0.0, and the description is "forked", the final client version string
630+
* will be "Pulsar-Java-v3.0.0-forked".
631+
*
632+
* @param description the description of the current PulsarClient instance
633+
* @throws IllegalArgumentException if the length of description exceeds 64
634+
*/
635+
ClientBuilder description(String description);
619636
}

pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,7 @@ public ClientBuilder socks5ProxyPassword(String socks5ProxyPassword) {
411411
return this;
412412
}
413413

414-
/**
415-
* Set the description.
416-
*
417-
* <p> By default, when the client connects to the broker, a version string like "Pulsar-Java-v<x.y.z>" will be
418-
* carried and saved by the broker. The client version string could be queried from the topic stats.
419-
*
420-
* <p> This method provides a way to add more description to a specific PulsarClient instance. If it's configured,
421-
* the description will be appended to the original client version string, with '-' as the separator.
422-
*
423-
* <p>For example, if the client version is 3.0.0, and the description is "forked", the final client version string
424-
* will be "Pulsar-Java-v3.0.0-forked".
425-
*
426-
* @param description the description of the current PulsarClient instance
427-
* @throws IllegalArgumentException if the length of description exceeds 64
428-
*/
414+
@Override
429415
public ClientBuilder description(String description) {
430416
if (description != null && description.length() > 64) {
431417
throw new IllegalArgumentException("description should be at most 64 characters");

0 commit comments

Comments
 (0)