You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/02/09 12:16:12 UTC

[GitHub] [pulsar] RobertIndie commented on a change in pull request #13355: [PIP-124] Create init subscription before sending message to DLQ

RobertIndie commented on a change in pull request #13355:
URL: https://github.com/apache/pulsar/pull/13355#discussion_r802599438



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1245,9 +1247,41 @@ protected void handleProducer(final CommandProducer cmdProducer) {
 
                     schemaVersionFuture.thenAccept(schemaVersion -> {
                         topic.checkIfTransactionBufferRecoverCompletely(isTxnEnabled).thenAccept(future -> {
-                            buildProducerAndAddTopic(topic, producerId, producerName, requestId, isEncrypted,
+                            CompletableFuture<Subscription> initSubFuture = new CompletableFuture<>();
+                            if (!Strings.isNullOrEmpty(initialSubscriptionName)
+                                    && !topic.getSubscriptions().containsKey(initialSubscriptionName)
+                                    && topic.isPersistent()) {
+                                initSubFuture = isTopicOperationAllowed(
+                                        topicName, TopicOperation.SUBSCRIBE
+                                ).thenCompose(canSubscribe -> {
+                                    if (!canSubscribe) {
+                                        return FutureUtil.failedFuture(
+                                                new BrokerServiceException.ProducerInitSubAuthorizationException(
+                                                        "Client is not authorized to subscribe."));
+                                    }
+                                    return topic.createSubscription(initialSubscriptionName, InitialPosition.Earliest,
+                                            false);
+                                });
+                            } else {
+                                initSubFuture.complete(null);
+                            }

Review comment:
       Thanks. I fixed it.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org