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 2021/11/22 07:23:20 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #12869: [PIP-105] Part-1 Support add subscription properties

codelipenghui commented on a change in pull request #12869:
URL: https://github.com/apache/pulsar/pull/12869#discussion_r753988280



##########
File path: pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
##########
@@ -551,6 +555,17 @@ public static ByteBuf newSubscribe(String topic, String subscription, long consu
                 .setReplicateSubscriptionState(isReplicated)
                 .setForceTopicCreation(createTopicIfDoesNotExist);
 
+        if (subscriptionProperties != null && subscriptionProperties.size() > 0) {

Review comment:
       nit:
   
   ```suggestion
           if (subscriptionProperties != null && !subscriptionProperties.isEmpty()) {
   ```

##########
File path: pulsar-common/src/main/proto/PulsarApi.proto
##########
@@ -382,6 +382,8 @@ message CommandSubscribe {
     optional uint64 start_message_rollback_duration_sec = 16 [default = 0];
 
     optional KeySharedMeta keySharedMeta = 17;
+
+    repeated KeyLongValue subscription_properties = 18;

Review comment:
       It should be KeyValue? If use KeyLongValue, we can only use `uint64` for the value.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SubscriptionOption.java
##########
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import lombok.Builder;
+import lombok.Data;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.common.api.proto.CommandSubscribe;
+import org.apache.pulsar.common.api.proto.KeyLongValue;
+import org.apache.pulsar.common.api.proto.KeySharedMeta;
+
+@Data
+@Builder
+public class SubscriptionOption {
+    final TransportCnx cnx;
+    String subscriptionName;
+    long consumerId;
+    CommandSubscribe.SubType subType;
+    int priorityLevel;
+    String consumerName;
+    boolean isDurable;
+    MessageId startMessageId;
+    Map<String, String> metadata;
+    boolean readCompacted;
+    CommandSubscribe.InitialPosition initialPosition;
+    long startMessageRollbackDurationSec;
+    boolean replicatedSubscriptionStateArg;
+    KeySharedMeta keySharedMeta;
+    Map<String, Long> subscriptionProperties;

Review comment:
       We should keep private access? since we exposed getter and setter by `@Data`
   
   And it's better to only apply `@Getter`? we are using the Builder to build the object

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java
##########
@@ -204,6 +204,13 @@ public ConsumerBuilderImpl(PulsarClientImpl client, Schema<T> schema) {
         return this;
     }
 
+    @Override
+    public ConsumerBuilder<T> subscriptionProperties(Map<String, Long> subscriptionProperties) {
+        checkArgument(subscriptionProperties != null, "subscriptionProperties cannot be null");
+        conf.setSubscriptionProperties(subscriptionProperties);

Review comment:
       ```suggestion
           conf.setSubscriptionProperties(Collections.unmodifiableMap(subscriptionProperties));
   ```

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SubscriptionOption.java
##########
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import lombok.Builder;
+import lombok.Data;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.common.api.proto.CommandSubscribe;
+import org.apache.pulsar.common.api.proto.KeyLongValue;
+import org.apache.pulsar.common.api.proto.KeySharedMeta;
+
+@Data
+@Builder
+public class SubscriptionOption {
+    final TransportCnx cnx;
+    String subscriptionName;
+    long consumerId;
+    CommandSubscribe.SubType subType;
+    int priorityLevel;
+    String consumerName;
+    boolean isDurable;
+    MessageId startMessageId;
+    Map<String, String> metadata;
+    boolean readCompacted;
+    CommandSubscribe.InitialPosition initialPosition;
+    long startMessageRollbackDurationSec;
+    boolean replicatedSubscriptionStateArg;
+    KeySharedMeta keySharedMeta;
+    Map<String, Long> subscriptionProperties;

Review comment:
       And we should change all the non-required fields to `Optional<>`?

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Topic.java
##########
@@ -137,6 +137,13 @@ default boolean isMarkerMessage() {
                                           long startMessageRollbackDurationSec, boolean replicateSubscriptionState,
                                           KeySharedMeta keySharedMeta);
 
+    /**
+     * Subscribe a topic.
+     * @param option
+     * @return
+     */
+    CompletableFuture<Consumer> subscribe(SubscriptionOption option);

Review comment:
       Looks like we can remove the old one to avoid interface complexity?

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java
##########
@@ -143,14 +145,20 @@ static boolean isCursorFromReplicatedSubscription(ManagedCursor cursor) {
     }
 
     public PersistentSubscription(PersistentTopic topic, String subscriptionName, ManagedCursor cursor,
-            boolean replicated) {
+                                                         boolean replicated) {
+        this(topic, subscriptionName, cursor, replicated, Collections.emptyMap());
+    }
+
+    public PersistentSubscription(PersistentTopic topic, String subscriptionName, ManagedCursor cursor,
+            boolean replicated, Map<String, Long> subscriptionProperties) {
         this.topic = topic;
         this.cursor = cursor;
         this.topicName = topic.getName();
         this.subName = subscriptionName;
         this.fullName = MoreObjects.toStringHelper(this).add("topic", topicName).add("name", subName).toString();
         this.expiryMonitor = new PersistentMessageExpiryMonitor(topicName, subscriptionName, cursor, this);
         this.setReplicated(replicated);
+        this.subscriptionProperties = subscriptionProperties == null ? new HashMap<>() : subscriptionProperties;

Review comment:
       ```suggestion
           this.subscriptionProperties = subscriptionProperties == null ? Collections.emptyMap() : Collections.unmodifiableMap(subscriptionProperties);
   ```




-- 
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