当前位置: 首页>>代码示例>>Java>>正文


Java TopicPartition.topic方法代码示例

本文整理汇总了Java中org.apache.kafka.common.TopicPartition.topic方法的典型用法代码示例。如果您正苦于以下问题:Java TopicPartition.topic方法的具体用法?Java TopicPartition.topic怎么用?Java TopicPartition.topic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.common.TopicPartition的用法示例。


在下文中一共展示了TopicPartition.topic方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pauseTopic

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
@Override
public void pauseTopic(TopicPartition tp, long offset, ControlMessage message) {

    String topic = message.payloadValue("topic", String.class);
    String tableName = message.payloadValue("TABLE_NAME", String.class);
    if (topic == null || topic.length() == 0) topic = tp.topic();
    if (!pausedTopics.containsKey(topic)) {
        consumer.pause(Arrays.asList(tp));
        TopicInfo topicInfo = TopicInfo.build(tp.topic(), tp.partition(), offset, tableName);
        pausedTopics.put(topic, topicInfo);

        try {
            zkNodeOperator.setData(pausedTopics, true);
        } catch (Exception e) {
            logger.error("Adding paused topics error", e);
        }
        logger.info("Topic [{}] was paused by command", tp.topic());
    } else {
        logger.info("Topic [{}] has been paused, the pause action was skipped", tp.topic());
    }
}
 
开发者ID:BriData,项目名称:DBus,代码行数:22,代码来源:AppenderConsumer.java

示例2: committedFileName

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
public static String committedFileName(String url, String topicsDir, String directory,
                                       TopicPartition topicPart, long startOffset, long endOffset,
                                       String extension, String zeroPadFormat) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  StringBuilder sb = new StringBuilder();
  sb.append(topic);
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(partition);
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(String.format(zeroPadFormat, startOffset));
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(String.format(zeroPadFormat, endOffset));
  sb.append(extension);
  String name = sb.toString();
  return fileName(url, topicsDir, directory, name);
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:18,代码来源:FileUtils.java

示例3: assign

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
@Override
public Map<String, List<TopicPartition>> assign(Map<String, Integer> partitionsPerTopic,
                                                Map<String, Subscription> subscriptions) {
    Map<String, List<TopicPartition>> assignment = new HashMap<>();
    for (String memberId : subscriptions.keySet())
        assignment.put(memberId, new ArrayList<TopicPartition>());

    CircularIterator<String> assigner = new CircularIterator<>(Utils.sorted(subscriptions.keySet()));
    for (TopicPartition partition : allPartitionsSorted(partitionsPerTopic, subscriptions)) {
        final String topic = partition.topic();
        while (!subscriptions.get(assigner.peek()).topics().contains(topic))
            assigner.next();
        assignment.get(assigner.next()).add(partition);
    }
    return assignment;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:RoundRobinAssignor.java

示例4: record

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
/**
 * After each partition is parsed, we update the current metric totals with the total bytes
 * and number of records parsed. After all partitions have reported, we write the metric.
 */
public void record(TopicPartition partition, int bytes, int records) {
    this.unrecordedPartitions.remove(partition);
    this.fetchMetrics.increment(bytes, records);

    // collect and aggregate per-topic metrics
    String topic = partition.topic();
    FetchMetrics topicFetchMetric = this.topicFetchMetrics.get(topic);
    if (topicFetchMetric == null) {
        topicFetchMetric = new FetchMetrics();
        this.topicFetchMetrics.put(topic, topicFetchMetric);
    }
    topicFetchMetric.increment(bytes, records);

    if (this.unrecordedPartitions.isEmpty()) {
        // once all expected partitions from the fetch have reported in, record the metrics
        this.sensors.bytesFetched.record(topicFetchMetric.fetchBytes);
        this.sensors.recordsFetched.record(topicFetchMetric.fetchRecords);

        // also record per-topic metrics
        for (Map.Entry<String, FetchMetrics> entry: this.topicFetchMetrics.entrySet()) {
            FetchMetrics metric = entry.getValue();
            this.sensors.recordTopicFetchMetrics(entry.getKey(), metric.fetchBytes, metric.fetchRecords);
        }
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:Fetcher.java

示例5: addToResetList

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
private void addToResetList(final TopicPartition partition, final Set<TopicPartition> partitions, final String logMessage, final String resetPolicy, final Set<String> loggedTopics) {
    final String topic = partition.topic();
    if (loggedTopics.add(topic)) {
        log.info(logMessage, logPrefix, topic, resetPolicy);
    }
    partitions.add(partition);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:StreamThread.java

示例6: removeMovementRecordOfPartition

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
private ConsumerPair removeMovementRecordOfPartition(TopicPartition partition) {
    ConsumerPair pair = partitionMovements.remove(partition);

    String topic = partition.topic();
    Map<ConsumerPair, Set<TopicPartition>> partitionMovementsForThisTopic = partitionMovementsByTopic.get(topic);
    partitionMovementsForThisTopic.get(pair).remove(partition);
    if (partitionMovementsForThisTopic.get(pair).isEmpty())
        partitionMovementsForThisTopic.remove(pair);
    if (partitionMovementsByTopic.get(topic).isEmpty())
        partitionMovementsByTopic.remove(topic);

    return pair;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:StickyAssignor.java

示例7: addPartitionMovementRecord

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
private void addPartitionMovementRecord(TopicPartition partition, ConsumerPair pair) {
    partitionMovements.put(partition, pair);

    String topic = partition.topic();
    if (!partitionMovementsByTopic.containsKey(topic))
        partitionMovementsByTopic.put(topic, new HashMap<ConsumerPair, Set<TopicPartition>>());

    Map<ConsumerPair, Set<TopicPartition>> partitionMovementsForThisTopic = partitionMovementsByTopic.get(topic);
    if (!partitionMovementsForThisTopic.containsKey(pair))
        partitionMovementsForThisTopic.put(pair, new HashSet<TopicPartition>());

    partitionMovementsForThisTopic.get(pair).add(partition);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:StickyAssignor.java

示例8: assign

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
/**
 * 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 the given list of topic partitions is empty, it is treated the same as {@link #unsubscribe()}.
 *
 * <p>
 * Manual topic assignment through this method does not use the consumer's group management
 * functionality. As such, there will be no rebalance operation triggered when group membership or cluster and topic
 * metadata change. Note that it is not possible to use both manual partition assignment with {@link #assign(Collection)}
 * and group assignment with {@link #subscribe(Collection, ConsumerRebalanceListener)}.
 *
 * @param partitions The list of partitions to assign this consumer
 * @throws IllegalArgumentException If partitions is null or contains null or empty topics
 */
@Override
// 用户手动订阅指定的topic并指定消费的分区,和subscribe方法互斥
public void assign(Collection<TopicPartition> partitions) {
    acquire();
    try {
        if (partitions == null) {
            throw new IllegalArgumentException("Topic partition collection to assign to cannot be null");
        } else if (partitions.isEmpty()) {
            this.unsubscribe();
        } else {
            Set<String> topics = new HashSet<>();
            for (TopicPartition tp : partitions) {
                String topic = (tp != null) ? tp.topic() : null;
                if (topic == null || topic.trim().isEmpty())
                    throw new IllegalArgumentException("Topic partitions to assign to cannot have null or empty topic");
                topics.add(topic);
            }

            // make sure the offsets of topic partitions the consumer is unsubscribing from
            // are committed since there will be no following rebalance
            this.coordinator.maybeAutoCommitOffsetsNow();

            log.debug("Subscribed to partition(s): {}", Utils.join(partitions, ", "));
            this.subscriptions.assignFromUser(new HashSet<>(partitions));
            metadata.setTopics(topics);
        }
    } finally {
        release();
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:46,代码来源:KafkaConsumer.java

示例9: groupDataByTopic

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
/**
 * group partitions by topic
 * @param partitions
 * @return partitions per topic
 */
public static Map<String, List<Integer>> groupDataByTopic(List<TopicPartition> partitions) {
    Map<String, List<Integer>> partitionsByTopic = new HashMap<>();
    for (TopicPartition tp: partitions) {
        String topic = tp.topic();
        List<Integer> topicData = partitionsByTopic.get(topic);
        if (topicData == null) {
            topicData = new ArrayList<>();
            partitionsByTopic.put(topic, topicData);
        }
        topicData.add(tp.partition());
    }
    return  partitionsByTopic;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:CollectionUtils.java

示例10: directoryName

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
public static String directoryName(String url, String topicsDir, TopicPartition topicPart) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  return url + "/" + topicsDir + "/" + topic + "/" + partition;
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:6,代码来源:FileUtils.java

示例11: fileName

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
public static String fileName(String url, String topicsDir, TopicPartition topicPart,
                              String name) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  return url + "/" + topicsDir + "/" + topic + "/" + partition + "/" + name;
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:7,代码来源:FileUtils.java

示例12: getOffsetQuarz

import org.apache.kafka.common.TopicPartition; //导入方法依赖的package包/类
public static List<OffsetInfo> getOffsetQuarz() {

        Map<String, Map<String, List<OffsetInfo>>> groupTopicPartitionListMap = new ConcurrentHashMap<>();

        for (Map.Entry<GroupTopicPartition, OffsetAndMetadata> entry: kafkaConsumerOffsets.entrySet()) {
            GroupTopicPartition groupTopicPartition = entry.getKey();
            OffsetAndMetadata offsetAndMetadata = entry.getValue();
            String group = groupTopicPartition.group();
            TopicPartition topicPartition = groupTopicPartition.topicPartition();
            String topic = topicPartition.topic();
            int partition = topicPartition.partition();
            Long committedOffset = offsetAndMetadata.offset();

            if (!logEndOffsetMap.containsKey(topicPartition)) {
                logger.error("The logEndOffsetMap not contains " + topicPartition);
                return null;
            }
            long logSize = logEndOffsetMap.get(topicPartition);

            // May the refresh operation thread take some time to update
            logSize = logSize >= committedOffset ? logSize : committedOffset;
            long lag = committedOffset == -1 ? 0 : (logSize - committedOffset);

            OffsetInfo offsetInfo = new OffsetInfo();
            offsetInfo.setGroup(group);
            offsetInfo.setTopic(topic);
            offsetInfo.setCommittedOffset(committedOffset);
            offsetInfo.setLogSize(logSize);
            offsetInfo.setLag(lag);
            offsetInfo.setTimestamp(offsetAndMetadata.commitTimestamp());

            if (!groupTopicPartitionListMap.containsKey(group)) {
                Map<String, List<OffsetInfo>> topicPartitionMap = new ConcurrentHashMap<>();
                groupTopicPartitionListMap.put(group, topicPartitionMap);
            }
            if (!groupTopicPartitionListMap.get(group).containsKey(topic)) {
                List<OffsetInfo> offsetInfos = new ArrayList<>();
                groupTopicPartitionListMap.get(group).put(topic, offsetInfos);
            }
            groupTopicPartitionListMap.get(group).get(topic).add(offsetInfo);

        }
        return flattenNestedMap(groupTopicPartitionListMap);
    }
 
开发者ID:dubin555,项目名称:Kafka-Insight,代码行数:45,代码来源:KafkaOffsetGetter.java


注:本文中的org.apache.kafka.common.TopicPartition.topic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。