Skip to content

Commit 65b3541

Browse files
authored
[fix][client] Add description method to ClientBuilder (#24728)
1 parent 415c6fa commit 65b3541

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
@@ -98,7 +98,6 @@
9898
import org.apache.pulsar.client.admin.PulsarAdminException;
9999
import org.apache.pulsar.client.api.schema.GenericRecord;
100100
import org.apache.pulsar.client.impl.BatchMessageIdImpl;
101-
import org.apache.pulsar.client.impl.ClientBuilderImpl;
102101
import org.apache.pulsar.client.impl.ConsumerBase;
103102
import org.apache.pulsar.client.impl.ConsumerImpl;
104103
import org.apache.pulsar.client.impl.MessageIdImpl;
@@ -4868,7 +4867,7 @@ public void testClientVersion() throws Exception {
48684867
assertEquals(stats.getPublishers().size(), 1);
48694868
assertEquals(stats.getPublishers().get(0).getClientVersion(), defaultClientVersion);
48704869

4871-
PulsarClient client = ((ClientBuilderImpl) PulsarClient.builder())
4870+
PulsarClient client = PulsarClient.builder()
48724871
.description("my-java-client")
48734872
.serviceUrl(lookupUrl.toString())
48744873
.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
@@ -717,4 +717,21 @@ ClientBuilder authentication(String authPluginClassName, Map<String, String> aut
717717
* - The `loadManagerClassName` config in broker is a class that implements the `ExtensibleLoadManager` interface
718718
*/
719719
ClientBuilder lookupProperties(Map<String, String> properties);
720+
721+
/**
722+
* Set the description.
723+
*
724+
* <p> By default, when the client connects to the broker, a version string like "Pulsar-Java-v<x.y.z>" will be
725+
* carried and saved by the broker. The client version string could be queried from the topic stats.
726+
*
727+
* <p> This method provides a way to add more description to a specific PulsarClient instance. If it's configured,
728+
* the description will be appended to the original client version string, with '-' as the separator.
729+
*
730+
* <p>For example, if the client version is 3.0.0, and the description is "forked", the final client version string
731+
* will be "Pulsar-Java-v3.0.0-forked".
732+
*
733+
* @param description the description of the current PulsarClient instance
734+
* @throws IllegalArgumentException if the length of description exceeds 64
735+
*/
736+
ClientBuilder description(String description);
720737
}

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
@@ -477,21 +477,7 @@ public ClientBuilder autoCertRefreshSeconds(int autoCertRefreshSeconds) {
477477
return this;
478478
}
479479

480-
/**
481-
* Set the description.
482-
*
483-
* <p> By default, when the client connects to the broker, a version string like "Pulsar-Java-v<x.y.z>" will be
484-
* carried and saved by the broker. The client version string could be queried from the topic stats.
485-
*
486-
* <p> This method provides a way to add more description to a specific PulsarClient instance. If it's configured,
487-
* the description will be appended to the original client version string, with '-' as the separator.
488-
*
489-
* <p>For example, if the client version is 3.0.0, and the description is "forked", the final client version string
490-
* will be "Pulsar-Java-v3.0.0-forked".
491-
*
492-
* @param description the description of the current PulsarClient instance
493-
* @throws IllegalArgumentException if the length of description exceeds 64
494-
*/
480+
@Override
495481
public ClientBuilder description(String description) {
496482
if (description != null && description.length() > 64) {
497483
throw new IllegalArgumentException("description should be at most 64 characters");

0 commit comments

Comments
 (0)