315157973 commented on a change in pull request #9163:
URL: https://github.com/apache/pulsar/pull/9163#discussion_r561529007
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -320,26 +320,31 @@ protected ConsumerImpl(PulsarClientImpl client, String
topic, ConsumerConfigurat
}
if (conf.getDeadLetterPolicy() != null) {
- possibleSendToDeadLetterTopicMessages = new ConcurrentHashMap<>();
- if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
-
.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic())
- .build();
+ // DLQ only supports non-ordered subscriptions, don't enable DLQ
on Key_Shared subType since it require message ordering for given key.
+ if (conf.getSubscriptionType() != SubscriptionType.Key_Shared) {
+ possibleSendToDeadLetterTopicMessages = new
ConcurrentHashMap<>();
} else {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
- .deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX, topic, subscription))
- .build();
+ possibleSendToDeadLetterTopicMessages = null;
+ }
+ DeadLetterPolicy.DeadLetterPolicyBuilder dlpBuilder =
DeadLetterPolicy.builder()
+
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount());
+
+
+ if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
+
dlpBuilder.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic());
+ } else if (conf.getSubscriptionType() !=
SubscriptionType.Key_Shared) {
+ // Not setting a default DLQ is it's Key_Shared subType.
+ dlpBuilder.deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX,
+ topic, subscription));
}
if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getRetryLetterTopic())) {
-
this.deadLetterPolicy.setRetryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
+
dlpBuilder.retryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
} else {
-
this.deadLetterPolicy.setRetryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
+ dlpBuilder.retryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
topic, subscription));
}
-
+ this.deadLetterPolicy = dlpBuilder.build();
Review comment:
If we disable it in the constructor and it is final, there is no need to
judge whether the following code
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -320,26 +320,31 @@ protected ConsumerImpl(PulsarClientImpl client, String
topic, ConsumerConfigurat
}
if (conf.getDeadLetterPolicy() != null) {
- possibleSendToDeadLetterTopicMessages = new ConcurrentHashMap<>();
- if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
-
.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic())
- .build();
+ // DLQ only supports non-ordered subscriptions, don't enable DLQ
on Key_Shared subType since it require message ordering for given key.
+ if (conf.getSubscriptionType() != SubscriptionType.Key_Shared) {
+ possibleSendToDeadLetterTopicMessages = new
ConcurrentHashMap<>();
} else {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
- .deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX, topic, subscription))
- .build();
+ possibleSendToDeadLetterTopicMessages = null;
+ }
+ DeadLetterPolicy.DeadLetterPolicyBuilder dlpBuilder =
DeadLetterPolicy.builder()
+
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount());
+
+
+ if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
+
dlpBuilder.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic());
+ } else if (conf.getSubscriptionType() !=
SubscriptionType.Key_Shared) {
+ // Not setting a default DLQ is it's Key_Shared subType.
+ dlpBuilder.deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX,
+ topic, subscription));
}
if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getRetryLetterTopic())) {
-
this.deadLetterPolicy.setRetryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
+
dlpBuilder.retryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
} else {
-
this.deadLetterPolicy.setRetryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
+ dlpBuilder.retryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
topic, subscription));
}
-
+ this.deadLetterPolicy = dlpBuilder.build();
Review comment:
If we disable it in the construction method and it is final, the
following code no longer needs to determine whether it is key_share. Is it
easier?
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -320,26 +320,31 @@ protected ConsumerImpl(PulsarClientImpl client, String
topic, ConsumerConfigurat
}
if (conf.getDeadLetterPolicy() != null) {
- possibleSendToDeadLetterTopicMessages = new ConcurrentHashMap<>();
- if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
-
.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic())
- .build();
+ // DLQ only supports non-ordered subscriptions, don't enable DLQ
on Key_Shared subType since it require message ordering for given key.
+ if (conf.getSubscriptionType() != SubscriptionType.Key_Shared) {
+ possibleSendToDeadLetterTopicMessages = new
ConcurrentHashMap<>();
} else {
- this.deadLetterPolicy = DeadLetterPolicy.builder()
-
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount())
- .deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX, topic, subscription))
- .build();
+ possibleSendToDeadLetterTopicMessages = null;
+ }
+ DeadLetterPolicy.DeadLetterPolicyBuilder dlpBuilder =
DeadLetterPolicy.builder()
+
.maxRedeliverCount(conf.getDeadLetterPolicy().getMaxRedeliverCount());
+
+
+ if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getDeadLetterTopic())) {
+
dlpBuilder.deadLetterTopic(conf.getDeadLetterPolicy().getDeadLetterTopic());
+ } else if (conf.getSubscriptionType() !=
SubscriptionType.Key_Shared) {
+ // Not setting a default DLQ is it's Key_Shared subType.
+ dlpBuilder.deadLetterTopic(String.format("%s-%s" +
RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX,
+ topic, subscription));
}
if
(StringUtils.isNotBlank(conf.getDeadLetterPolicy().getRetryLetterTopic())) {
-
this.deadLetterPolicy.setRetryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
+
dlpBuilder.retryLetterTopic(conf.getDeadLetterPolicy().getRetryLetterTopic());
} else {
-
this.deadLetterPolicy.setRetryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
+ dlpBuilder.retryLetterTopic(String.format("%s-%s" +
RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX,
topic, subscription));
}
-
+ this.deadLetterPolicy = dlpBuilder.build();
Review comment:
I mean, we let DQL only be modified in the constructor. There will be no
way to modify it in the future. In this way, we only need to judge whether it
is legal in the construction method. In the logic behind, we don’t need to care
about key-share anymore, because it will definitely not be key-share
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]