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



##########
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:
       we remove the topic param, simpleConsumer must subscribe before receive.




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


Reply via email to