jimmydivvy commented on a change in pull request #14433:
URL: https://github.com/apache/pulsar/pull/14433#discussion_r813489185
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java
##########
@@ -119,52 +118,58 @@ public ConsumerBuilderImpl(PulsarClientImpl client,
Schema<T> schema) {
return FutureUtil.failedFuture(
new InvalidConfigurationException("KeySharedPolicy must
set with KeyShared subscription"));
}
+ CompletableFuture<Void> applyDLQConfig;
if (conf.isRetryEnable() && conf.getTopicNames().size() > 0) {
TopicName topicFirst =
TopicName.get(conf.getTopicNames().iterator().next());
- String retryLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX;
- String deadLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX;
+ AtomicReference<String> retryLetterTopic =
Review comment:
You can possibly return the relevant result from the Future itself
without needing a Ref here.
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java
##########
@@ -119,52 +118,58 @@ public ConsumerBuilderImpl(PulsarClientImpl client,
Schema<T> schema) {
return FutureUtil.failedFuture(
new InvalidConfigurationException("KeySharedPolicy must
set with KeyShared subscription"));
}
+ CompletableFuture<Void> applyDLQConfig;
if (conf.isRetryEnable() && conf.getTopicNames().size() > 0) {
TopicName topicFirst =
TopicName.get(conf.getTopicNames().iterator().next());
- String retryLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX;
- String deadLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX;
+ AtomicReference<String> retryLetterTopic =
+ new AtomicReference<>(topicFirst + "-" +
conf.getSubscriptionName()
+ + RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX);
+ AtomicReference<String> deadLetterTopic =
+ new AtomicReference<>(topicFirst + "-" +
conf.getSubscriptionName()
+ + RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX);
//Issue 9327: do compatibility check in case of the default retry
and dead letter topic name changed
String oldRetryLetterTopic = topicFirst.getNamespace() + "/" +
conf.getSubscriptionName()
+ RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX;
String oldDeadLetterTopic = topicFirst.getNamespace() + "/" +
conf.getSubscriptionName()
+ RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX;
- try {
- if (client.getPartitionedTopicMetadata(oldRetryLetterTopic)
- .get(client.conf.getOperationTimeoutMs(),
TimeUnit.MILLISECONDS).partitions > 0) {
- retryLetterTopic = oldRetryLetterTopic;
- }
- if (client.getPartitionedTopicMetadata(oldDeadLetterTopic)
- .get(client.conf.getOperationTimeoutMs(),
TimeUnit.MILLISECONDS).partitions > 0) {
- deadLetterTopic = oldDeadLetterTopic;
- }
- } catch (InterruptedException | TimeoutException e) {
- return FutureUtil.failedFuture(e);
- } catch (ExecutionException e) {
- return FutureUtil.failedFuture(e.getCause());
- }
-
- if (conf.getDeadLetterPolicy() == null) {
- conf.setDeadLetterPolicy(DeadLetterPolicy.builder()
-
.maxRedeliverCount(RetryMessageUtil.MAX_RECONSUMETIMES)
- .retryLetterTopic(retryLetterTopic)
- .deadLetterTopic(deadLetterTopic)
- .build());
+ applyDLQConfig =
client.getPartitionedTopicMetadata(oldRetryLetterTopic)
Review comment:
Is it worth making both `getPartitionedTopicMetadata` calls
concurrently?
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java
##########
@@ -119,52 +118,58 @@ public ConsumerBuilderImpl(PulsarClientImpl client,
Schema<T> schema) {
return FutureUtil.failedFuture(
new InvalidConfigurationException("KeySharedPolicy must
set with KeyShared subscription"));
}
+ CompletableFuture<Void> applyDLQConfig;
if (conf.isRetryEnable() && conf.getTopicNames().size() > 0) {
TopicName topicFirst =
TopicName.get(conf.getTopicNames().iterator().next());
- String retryLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX;
- String deadLetterTopic =
- topicFirst + "-" + conf.getSubscriptionName() +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX;
+ AtomicReference<String> retryLetterTopic =
+ new AtomicReference<>(topicFirst + "-" +
conf.getSubscriptionName()
+ + RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX);
+ AtomicReference<String> deadLetterTopic =
+ new AtomicReference<>(topicFirst + "-" +
conf.getSubscriptionName()
+ + RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX);
//Issue 9327: do compatibility check in case of the default retry
and dead letter topic name changed
String oldRetryLetterTopic = topicFirst.getNamespace() + "/" +
conf.getSubscriptionName()
+ RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX;
String oldDeadLetterTopic = topicFirst.getNamespace() + "/" +
conf.getSubscriptionName()
+ RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX;
- try {
- if (client.getPartitionedTopicMetadata(oldRetryLetterTopic)
- .get(client.conf.getOperationTimeoutMs(),
TimeUnit.MILLISECONDS).partitions > 0) {
- retryLetterTopic = oldRetryLetterTopic;
- }
- if (client.getPartitionedTopicMetadata(oldDeadLetterTopic)
- .get(client.conf.getOperationTimeoutMs(),
TimeUnit.MILLISECONDS).partitions > 0) {
- deadLetterTopic = oldDeadLetterTopic;
- }
- } catch (InterruptedException | TimeoutException e) {
- return FutureUtil.failedFuture(e);
- } catch (ExecutionException e) {
- return FutureUtil.failedFuture(e.getCause());
- }
-
- if (conf.getDeadLetterPolicy() == null) {
- conf.setDeadLetterPolicy(DeadLetterPolicy.builder()
-
.maxRedeliverCount(RetryMessageUtil.MAX_RECONSUMETIMES)
- .retryLetterTopic(retryLetterTopic)
- .deadLetterTopic(deadLetterTopic)
- .build());
+ applyDLQConfig =
client.getPartitionedTopicMetadata(oldRetryLetterTopic)
Review comment:
We should also only make the call if the topic isn't already defined in
the conf explicitly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]