接口 PullConsumer

  • 所有超级接口:
    Admin

    public interface PullConsumer
    extends Admin
    • 方法详细资料

      • topicPartitions

        Set<TopicPartition> topicPartitions​(String topic)
        Get metadata about the partitions 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.
        参数:
        topic - message's topic
        返回:
        partitions of topic.
      • assign

        void assign​(Collection<TopicPartition> topicPartitions)
        Manually assign a list of partitions to this consumer. This interface does not allow for incremental assignment and will replace the previous assignment (if there is one).

        If auto-commit is enabled, an async commit (based on the old assignment) will be triggered before the new assignment replaces the old one.

        参数:
        topicPartitions - partitions of topic.
      • registerTopicPartitionChangedListener

        void registerTopicPartitionChangedListener​(String topic,
                                                   PullConsumer.TopicPartitionChangeListener callback)
        Register a callback for sensing topic metadata changes.
        参数:
        topic - message's topic
        callback - callback to receive notification when partition is changed.
      • poll

        List<Message> poll​(long timeout)
        Fetch data for the topics or partitions specified using assign API. It is an error to not have subscribed to any topics or partitions before polling for data.
        参数:
        timeout - in millisecond
        返回:
        fetch messages of appointed topic.
      • seek

        void seek​(TopicPartition topicPartition,
                  long offset)
        Overrides the fetch offsets that the consumer will use on the next poll(long) }. If this API is invoked for the same message queue more than once, the latest offset will be used on the next poll(). Note that you may lose data if this API is arbitrarily used in the middle of consumption.
        参数:
        topicPartition - partitions of topic.
        offset - offset to seek.
      • seekToBeginning

        void seekToBeginning​(TopicPartition topicPartition)
        Overrides the fetch offsets with the beginning offset in server that the consumer will use on the next poll(long) }.
        参数:
        topicPartition - partitions of topic.
      • seekToEnd

        void seekToEnd​(TopicPartition topicPartition)
        Overrides the fetch offsets with the end offset in server that the consumer will use on the next poll(long) }.
        参数:
        topicPartition - partitions of topic.
      • pause

        void pause​(Collection<TopicPartition> topicPartitions)
        Suspend fetching from the requested message queues. Future calls to poll(long) will not return any records from these message queues until they have been resumed using resume(Collection).

        Note that this method does not affect message queue subscription. In particular, it does not cause a group rebalance.

        参数:
        topicPartitions - partitions of topic.
      • resume

        void resume​(Collection<TopicPartition> topicPartitions)
        Resume specified message queues which have been paused with pause(Collection). New calls to poll(long) will return records from these partitions if there are any to be fetched. If the message queues were not previously paused, this method is a no-op.
        参数:
        topicPartitions - partitions of topic.
      • offsetForTimestamp

        Long offsetForTimestamp​(TopicPartition topicPartition,
                                Long timestamp)
        Look up the offsets for the given message queue by timestamp. The returned offset for each message queue is the earliest offset whose timestamp is greater than or equal to the given timestamp in the corresponding message queue.
        参数:
        topicPartition - partitions of topic.
        timestamp - timestamp to look up offsets.
        返回:
        offset
      • committed

        Long committed​(TopicPartition topicPartition)
        Get the last committed offset for the given message queue (whether the commit happened by this process or another). This offset will be used as the position for the consumer in the event of a failure.
        参数:
        topicPartition - partitions of topic.
        返回:
        the latest committed.
      • commitSync

        void commitSync()
        Sync commit current consumed offset to server.