You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/03/22 09:22:28 UTC

[GitHub] [rocketmq] dongeforever commented on a change in pull request #4019: [RIP-37] Add new APIs for consumer

dongeforever commented on a change in pull request #4019:
URL: https://github.com/apache/rocketmq/pull/4019#discussion_r831924772



##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/PullConsumer.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import java.io.Closeable;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.rocketmq.apis.MessageQueue;
+import org.apache.rocketmq.apis.exception.*;
+import org.apache.rocketmq.apis.message.MessageView;
+
+/**
+ * PullConsumer is a thread-safe rocketmq client which is used to consume message by queue.
+ * Unlike push consumer and simple consumer, pull consumer implement load balance based on queue granularity.
+ *
+ * <p>Pull consumer is lightweight consumer that better suited to streaming scenarios.
+ * If you want fully control the message consumption operation by yourself like scan by offset or reconsume repeatedly,
+ * pull consumer should be your first consideration.
+ *
+ * <p>Pull consumer support two load balance mode. First is subscription mode, which full manage the rebalance
+ * operation triggered when group membership or cluster and topic metadata change.Another mode is manual assignment mode,which manage the load balance by yourself.
+ *
+ * <p> Pull consumer divide message consumption to 3 parts.
+ * Firstly, determine whether to continue processing from the last consumption or reset the consumption starting point by call seek method;
+ * Then, pull message from servers.
+ * At last, pull consumer no need to commit message by offset meta.
+ * If there is a consumption error, consumer just call seek api to reset the offset for reconsume message again.
+ */
+public interface PullConsumer extends Closeable {
+    /**
+     * Listener that listens for changes of message queues when use manual assignment mode.
+     */
+    interface MessageQueuesChangeListener {
+        /**
+         * This method will be invoked in the condition of message queues changed, These scenarios occur when the
+         * topic is expanded or shrunk.
+         *
+         * @param messageQueues {@link MessageQueue} of topic.
+         */
+        void onChanged(Collection<MessageQueue> messageQueues);
+    }
+
+    /**
+     * Get metadata about the message queues for a given topic. This method will issue a remote call to the server if it
+     * does not already have any metadata about the given topic.
+     *
+     * @param topic message's topic
+     * @return message queues of topic.
+     */
+    Collection<MessageQueue> topicMessageQueues(String topic) throws ClientException;
+
+    /**
+     * Manually assign messageQueue collections to this consumer.
+     * This interface does not allow for incremental assignment and will replace the previous assignment.
+     * If the given collection is empty, it's treated same as unsubscribe().
+     * Manual assignment through this interface will disable the consumerGroup management functionality
+     * and there will be no rebalance operation triggered when group membership or cluster and topic metadata change.
+     * @param messageQueues are the collection for current consumer.
+     * @throws ClientException when assign
+     */
+    void assign(Collection<MessageQueue> messageQueues) throws ClientException;
+
+    /**
+     * Pull consumer query and update metadata about message queues periodically, listener is triggered once metadata
+     * is updated. The listener is required only in manual assignment mode.
+     * When use the subscription mode, no need to care the messageQueue change events.
+     *
+     * @param topic    topic to query and update metadata.
+     * @param listener listener to receive changes of metadata by topic.
+     */
+    void registerMessageQueuesChangeListener(String topic, MessageQueuesChangeListener listener);
+
+    /**
+     * Add subscription expression dynamically when use subscription mode.
+     *
+     * <p>If first {@link SubscriptionExpression} that contains topicA and tag1 is exists already in consumer, then
+     * second {@link SubscriptionExpression} which contains topicA and tag2, <strong>the result is that the second one
+     * replaces the first one instead of integrating them</strong>.
+     *
+     * @param subscriptionExpression new subscription expression to add.
+     * @return pull consumer instance.
+     */
+    PullConsumer subscribe(SubscriptionExpression subscriptionExpression) throws ClientException;
+
+    /**
+     * Remove subscription expression dynamically by topic.
+     *
+     * <p>Nothing occurs if the specified topic does not exist in subscription expressions of pull consumer.
+     *
+     * @param topic the topic to remove subscription.
+     * @return pull consumer instance.
+     */
+    PullConsumer unsubscribe(String topic) throws ClientException;
+
+    /**
+     * Get the collection of messageQueues currently assigned to current consumer.
+     * @return the collection of messageQueues currently assigned to current consumer
+     */
+    Collection<MessageQueue> assignment();
+
+    /**
+     * Fetch messages from server synchronously. This method returns immediately if there are messages available.
+     * Otherwise, it will await the passed timeout. If the timeout expires, an empty map will be returned.
+     * An error occurs if you do not subscribe or assign messageQueues before polling for data.
+     * @param messageQueue the target messageQueue to pull message.
+     * @param maxMessageNum max message num when server returns.
+     * @return collection of messageViews of this queue.
+     */
+    Collection<MessageView> pull(MessageQueue messageQueue, int maxMessageNum) throws ClientException;
+
+    /**
+     * Commit the offsets for the specified messageQueue.
+     * @param messageQueue the specified messageQueue to commit offset

Review comment:
       The streaming scenario needs a simple poll(ms) instead of the pull(messagequeue). 
   
   The user does not need to know the messagequeue at each pull. 
   And, the user may need to handle the queue changement, which is not necessary in most cases.
   More importantly, the underlying pull request will be polished as a batch mode to improve performance, which means one request may contain several messagequeues.
   
   This consumer is better to be named as PollConsumer.  Poll means to reduce one by one. 

##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/PushConsumer.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import com.google.common.util.concurrent.Service;
+import java.io.Closeable;
+import java.util.Collection;
+
+import org.apache.rocketmq.apis.exception.*;
+
+/**
+ * PushConsumer is a thread-safe rocketmq client which is used to consume message by group.
+ *
+ * <p>Push consumer is fully-managed consumer, if you are confused to choose your consumer, push consumer should be
+ * your first consideration.
+ *
+ * <p>Consumers belong to the same consumer group share messages from server,
+ * so consumer in the same group must have the same {@link SubscriptionExpression}s, otherwise the behavior is
+ * undefined. If a new consumer group's consumer is started first time, it consumes from the latest position. Once
+ * consumer is started, server records its consumption progress and derives it in subsequent startup.
+ *
+ * <p>You may intend to maintain different consumption progress for different consumer, different consumer group
+ * should be set in this case.
+ *
+ * <p>To accelerate the message consumption, push consumer applies
+ * <a href="https://en.wikipedia.org/wiki/Reactive_Streams">reactive streams</a>
+ * . Messages received from server is cached locally before consumption,
+ * {@link PushConsumerBuilder#setMaxCacheMessageCount(int)} and
+ * {@link PushConsumerBuilder#setMaxCacheMessageSizeInBytes(int)} could be used to set the cache threshold in
+ * different dimension.
+ */
+public interface PushConsumer extends Closeable {
+    /**
+     * Get the load balancing group for consumer.
+     *
+     * @return consumer load balancing group.
+     */
+    String getConsumerGroup();
+
+    /**
+     * Get the existed subscription expression in push consumer.
+     *
+     * @return collections of subscription expression.
+     */
+    Collection<SubscriptionExpression> listSubscriptionExpression();
+
+    /**
+     * Add subscription expression dynamically.
+     *
+     * <p>If first {@link SubscriptionExpression} that contains topicA and tag1 is exists already in consumer, then
+     * second {@link SubscriptionExpression} which contains topicA and tag2, <strong>the result is that the second one
+     * replaces the first one instead of integrating them</strong>.
+     *
+     * @param subscriptionExpression new subscription expression to add.
+     * @return push consumer instance.
+     */
+    PushConsumer subscribe(SubscriptionExpression subscriptionExpression) throws ClientException;
+
+    /**
+     * Remove subscription expression dynamically by topic.
+     *
+     * <p>It stops the backend task to fetch message from remote, and besides that, the local cached message whose topic
+     * was removed before would not be delivered to {@link MessageListener} anymore.
+     *
+     * <p>Nothing occurs if the specified topic does not exist in subscription expressions of push consumer.
+     *
+     * @param topic the topic to remove subscription.
+     * @return push consumer instance.
+     */
+    PushConsumer unsubscribe(String topic) throws ClientException;
+
+    /**
+     * Close the push consumer and release all related resources.
+     *
+     * <p>Once push consumer is closed, <strong>it could not be started once again.</strong> we maintained an FSM
+     * (finite-state machine) to record the different states for each producer, which is similar to
+     * {@link Service.State}.
+     */

Review comment:
       Maybe we need to get the MessageListenner.

##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/PullConsumer.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import java.io.Closeable;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.rocketmq.apis.MessageQueue;
+import org.apache.rocketmq.apis.exception.*;
+import org.apache.rocketmq.apis.message.MessageView;
+
+/**
+ * PullConsumer is a thread-safe rocketmq client which is used to consume message by queue.
+ * Unlike push consumer and simple consumer, pull consumer implement load balance based on queue granularity.
+ *
+ * <p>Pull consumer is lightweight consumer that better suited to streaming scenarios.
+ * If you want fully control the message consumption operation by yourself like scan by offset or reconsume repeatedly,
+ * pull consumer should be your first consideration.
+ *
+ * <p>Pull consumer support two load balance mode. First is subscription mode, which full manage the rebalance
+ * operation triggered when group membership or cluster and topic metadata change.Another mode is manual assignment mode,which manage the load balance by yourself.
+ *
+ * <p> Pull consumer divide message consumption to 3 parts.
+ * Firstly, determine whether to continue processing from the last consumption or reset the consumption starting point by call seek method;
+ * Then, pull message from servers.
+ * At last, pull consumer no need to commit message by offset meta.
+ * If there is a consumption error, consumer just call seek api to reset the offset for reconsume message again.
+ */
+public interface PullConsumer extends Closeable {
+    /**
+     * Listener that listens for changes of message queues when use manual assignment mode.
+     */
+    interface MessageQueuesChangeListener {
+        /**
+         * This method will be invoked in the condition of message queues changed, These scenarios occur when the
+         * topic is expanded or shrunk.
+         *
+         * @param messageQueues {@link MessageQueue} of topic.
+         */
+        void onChanged(Collection<MessageQueue> messageQueues);
+    }
+
+    /**
+     * Get metadata about the message queues for a given topic. This method will issue a remote call to the server if it
+     * does not already have any metadata about the given topic.
+     *
+     * @param topic message's topic
+     * @return message queues of topic.
+     */
+    Collection<MessageQueue> topicMessageQueues(String topic) throws ClientException;
+
+    /**
+     * Manually assign messageQueue collections to this consumer.
+     * This interface does not allow for incremental assignment and will replace the previous assignment.
+     * If the given collection is empty, it's treated same as unsubscribe().
+     * Manual assignment through this interface will disable the consumerGroup management functionality
+     * and there will be no rebalance operation triggered when group membership or cluster and topic metadata change.
+     * @param messageQueues are the collection for current consumer.
+     * @throws ClientException when assign
+     */
+    void assign(Collection<MessageQueue> messageQueues) throws ClientException;
+
+    /**
+     * Pull consumer query and update metadata about message queues periodically, listener is triggered once metadata
+     * is updated. The listener is required only in manual assignment mode.
+     * When use the subscription mode, no need to care the messageQueue change events.
+     *
+     * @param topic    topic to query and update metadata.
+     * @param listener listener to receive changes of metadata by topic.
+     */
+    void registerMessageQueuesChangeListener(String topic, MessageQueuesChangeListener listener);
+
+    /**
+     * Add subscription expression dynamically when use subscription mode.
+     *
+     * <p>If first {@link SubscriptionExpression} that contains topicA and tag1 is exists already in consumer, then
+     * second {@link SubscriptionExpression} which contains topicA and tag2, <strong>the result is that the second one
+     * replaces the first one instead of integrating them</strong>.
+     *
+     * @param subscriptionExpression new subscription expression to add.
+     * @return pull consumer instance.
+     */
+    PullConsumer subscribe(SubscriptionExpression subscriptionExpression) throws ClientException;
+
+    /**
+     * Remove subscription expression dynamically by topic.
+     *
+     * <p>Nothing occurs if the specified topic does not exist in subscription expressions of pull consumer.
+     *
+     * @param topic the topic to remove subscription.
+     * @return pull consumer instance.
+     */
+    PullConsumer unsubscribe(String topic) throws ClientException;
+
+    /**
+     * Get the collection of messageQueues currently assigned to current consumer.
+     * @return the collection of messageQueues currently assigned to current consumer
+     */
+    Collection<MessageQueue> assignment();
+
+    /**
+     * Fetch messages from server synchronously. This method returns immediately if there are messages available.
+     * Otherwise, it will await the passed timeout. If the timeout expires, an empty map will be returned.
+     * An error occurs if you do not subscribe or assign messageQueues before polling for data.
+     * @param messageQueue the target messageQueue to pull message.
+     * @param maxMessageNum max message num when server returns.
+     * @return collection of messageViews of this queue.
+     */
+    Collection<MessageView> pull(MessageQueue messageQueue, int maxMessageNum) throws ClientException;
+
+    /**
+     * Commit the offsets for the specified messageQueue.
+     * @param messageQueue the specified messageQueue to commit offset
+     * @param committedOffset the specified offset commit to server
+     */
+    void commit(MessageQueue messageQueue, long committedOffset) throws ClientException;

Review comment:
       The commit needs an async method.
   
   And more importantly, it needs a simple commit().
   
   In most cases, the user only wants to control the commit time but doesn't want to manage the offset store.
   

##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/PushConsumer.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import com.google.common.util.concurrent.Service;
+import java.io.Closeable;
+import java.util.Collection;
+
+import org.apache.rocketmq.apis.exception.*;
+
+/**
+ * PushConsumer is a thread-safe rocketmq client which is used to consume message by group.
+ *
+ * <p>Push consumer is fully-managed consumer, if you are confused to choose your consumer, push consumer should be
+ * your first consideration.
+ *
+ * <p>Consumers belong to the same consumer group share messages from server,
+ * so consumer in the same group must have the same {@link SubscriptionExpression}s, otherwise the behavior is
+ * undefined. If a new consumer group's consumer is started first time, it consumes from the latest position. Once
+ * consumer is started, server records its consumption progress and derives it in subsequent startup.
+ *
+ * <p>You may intend to maintain different consumption progress for different consumer, different consumer group
+ * should be set in this case.
+ *
+ * <p>To accelerate the message consumption, push consumer applies
+ * <a href="https://en.wikipedia.org/wiki/Reactive_Streams">reactive streams</a>
+ * . Messages received from server is cached locally before consumption,
+ * {@link PushConsumerBuilder#setMaxCacheMessageCount(int)} and
+ * {@link PushConsumerBuilder#setMaxCacheMessageSizeInBytes(int)} could be used to set the cache threshold in
+ * different dimension.
+ */
+public interface PushConsumer extends Closeable {
+    /**
+     * Get the load balancing group for consumer.
+     *
+     * @return consumer load balancing group.
+     */
+    String getConsumerGroup();
+
+    /**
+     * Get the existed subscription expression in push consumer.
+     *
+     * @return collections of subscription expression.
+     */
+    Collection<SubscriptionExpression> listSubscriptionExpression();
+
+    /**
+     * Add subscription expression dynamically.
+     *
+     * <p>If first {@link SubscriptionExpression} that contains topicA and tag1 is exists already in consumer, then
+     * second {@link SubscriptionExpression} which contains topicA and tag2, <strong>the result is that the second one
+     * replaces the first one instead of integrating them</strong>.
+     *
+     * @param subscriptionExpression new subscription expression to add.
+     * @return push consumer instance.
+     */
+    PushConsumer subscribe(SubscriptionExpression subscriptionExpression) throws ClientException;
+
+    /**
+     * Remove subscription expression dynamically by topic.
+     *
+     * <p>It stops the backend task to fetch message from remote, and besides that, the local cached message whose topic
+     * was removed before would not be delivered to {@link MessageListener} anymore.
+     *
+     * <p>Nothing occurs if the specified topic does not exist in subscription expressions of push consumer.
+     *
+     * @param topic the topic to remove subscription.
+     * @return push consumer instance.
+     */
+    PushConsumer unsubscribe(String topic) throws ClientException;
+

Review comment:
       Why do subscribe and unsubscribe have different arguments?
   
   It is a little strange intuitively.
   

##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/PullConsumer.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import java.io.Closeable;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.rocketmq.apis.MessageQueue;
+import org.apache.rocketmq.apis.exception.*;
+import org.apache.rocketmq.apis.message.MessageView;
+
+/**
+ * PullConsumer is a thread-safe rocketmq client which is used to consume message by queue.
+ * Unlike push consumer and simple consumer, pull consumer implement load balance based on queue granularity.
+ *
+ * <p>Pull consumer is lightweight consumer that better suited to streaming scenarios.
+ * If you want fully control the message consumption operation by yourself like scan by offset or reconsume repeatedly,
+ * pull consumer should be your first consideration.
+ *
+ * <p>Pull consumer support two load balance mode. First is subscription mode, which full manage the rebalance
+ * operation triggered when group membership or cluster and topic metadata change.Another mode is manual assignment mode,which manage the load balance by yourself.
+ *
+ * <p> Pull consumer divide message consumption to 3 parts.
+ * Firstly, determine whether to continue processing from the last consumption or reset the consumption starting point by call seek method;
+ * Then, pull message from servers.
+ * At last, pull consumer no need to commit message by offset meta.
+ * If there is a consumption error, consumer just call seek api to reset the offset for reconsume message again.
+ */
+public interface PullConsumer extends Closeable {
+    /**
+     * Listener that listens for changes of message queues when use manual assignment mode.
+     */
+    interface MessageQueuesChangeListener {
+        /**
+         * This method will be invoked in the condition of message queues changed, These scenarios occur when the
+         * topic is expanded or shrunk.
+         *
+         * @param messageQueues {@link MessageQueue} of topic.
+         */
+        void onChanged(Collection<MessageQueue> messageQueues);
+    }
+
+    /**
+     * Get metadata about the message queues for a given topic. This method will issue a remote call to the server if it
+     * does not already have any metadata about the given topic.
+     *
+     * @param topic message's topic
+     * @return message queues of topic.
+     */
+    Collection<MessageQueue> topicMessageQueues(String topic) throws ClientException;
+
+    /**
+     * Manually assign messageQueue collections to this consumer.
+     * This interface does not allow for incremental assignment and will replace the previous assignment.
+     * If the given collection is empty, it's treated same as unsubscribe().
+     * Manual assignment through this interface will disable the consumerGroup management functionality
+     * and there will be no rebalance operation triggered when group membership or cluster and topic metadata change.
+     * @param messageQueues are the collection for current consumer.
+     * @throws ClientException when assign
+     */
+    void assign(Collection<MessageQueue> messageQueues) throws ClientException;
+
+    /**
+     * Pull consumer query and update metadata about message queues periodically, listener is triggered once metadata
+     * is updated. The listener is required only in manual assignment mode.
+     * When use the subscription mode, no need to care the messageQueue change events.
+     *
+     * @param topic    topic to query and update metadata.
+     * @param listener listener to receive changes of metadata by topic.
+     */
+    void registerMessageQueuesChangeListener(String topic, MessageQueuesChangeListener listener);
+

Review comment:
       Why need to specify the topic argument?

##########
File path: apis/src/main/java/org/apache/rocketmq/apis/consumer/SimpleConsumer.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.rocketmq.apis.consumer;
+
+import java.io.Closeable;
+import java.time.Duration;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.rocketmq.apis.exception.*;
+import org.apache.rocketmq.apis.message.MessageView;
+
+/**
+ * SimpleConsumer is a thread-safe rocketmq client which is used to consume message by group.
+ *
+ * <p>Simple consumer is lightweight consumer , if you want fully control the message consumption operation by yourself,
+ * simple consumer should be your first consideration.
+ *
+ * <p>Consumers belong to the same consumer group share messages from server,
+ * so consumer in the same group must have the same {@link SubscriptionExpression}s, otherwise the behavior is
+ * undefined. If a new consumer group's consumer is started first time, it consumes from the latest position. Once
+ * consumer is started, server records its consumption progress and derives it in subsequent startup.
+ *
+ * <p>You may intend to maintain different consumption progress for different consumer, different consumer group
+ * should be set in this case.
+ *
+ * <p> Simple consumer divide message consumption to 3 parts.
+ * Firstly, call receive api get messages from server; Then process message by yourself; At last, your must call Ack api to commit this message.
+ * If there is error when process message ,your can reconsume the message later which control by the invisibleDuration parameter.
+ * Also, you can change the invisibleDuration by call changeInvisibleDuration api.
+ */
+public interface SimpleConsumer extends Closeable {
+    /**
+     * Get the load balancing group for simple consumer.
+     *
+     * @return consumer load balancing group.
+     */
+    String getConsumerGroup();
+
+    /**
+     * Add subscription expression dynamically.
+     *
+     * <p>If first {@link SubscriptionExpression} that contains topicA and tag1 is exists already in consumer, then
+     * second {@link SubscriptionExpression} which contains topicA and tag2, <strong>the result is that the second one
+     * replaces the first one instead of integrating them</strong>.
+     *
+     * @param subscriptionExpression new subscription expression to add.
+     * @return simple consumer instance.
+     */
+    SimpleConsumer subscribe(SubscriptionExpression subscriptionExpression) throws ClientException;
+
+    /**
+     * Remove subscription expression dynamically by topic.
+     *
+     * <p>It stops the backend task to fetch message from remote, and besides that, the local cached message whose topic
+     * was removed before would not be delivered to {@link MessageListener} anymore.
+     *
+     * <p>Nothing occurs if the specified topic does not exist in subscription expressions of push consumer.
+     *
+     * @param topic the topic to remove subscription.
+     * @return simple consumer instance.
+     */
+    SimpleConsumer unsubscribe(String topic) throws ClientException;
+
+    /**
+     * Fetch messages from server synchronously. This method returns immediately if there are messages available.
+     * Otherwise, it will await the passed timeout. If the timeout expires, an empty map will be returned.
+     * @param topic special topic want to get messages.
+     * @param maxMessageNum max message num when server returns.
+     * @param invisibleDuration set the invisibleDuration of messages return from server. These messages will be invisible to other consumer unless timout.
+     * @return list of messageView
+     */
+    List<MessageView> receive(String topic, int maxMessageNum, Duration invisibleDuration) throws ClientException;
+
+    /**

Review comment:
       What's the relationship between the topic in receive and topic in subcribe/unsubscribe.




-- 
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: dev-unsubscribe@rocketmq.apache.org

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