chenzlalvin commented on a change in pull request #4019: URL: https://github.com/apache/rocketmq/pull/4019#discussion_r832745565
########## 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: Maybe we need to rethink of the design of PullConsumer. -- 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]
