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


Java OffsetRequest.LatestTime方法代码示例

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


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

示例1: generateTsOffsetsNoPartitions

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
private List<long[]> generateTsOffsetsNoPartitions(final long scanRange,
                                                   final int partitionNum)
{
    // we want to increase the number of splits so that it can achieve maximum parallelism
    // the idle number would be splits == cores
    // TODO make this configerable
    final int numHosts = 40;
    final int numCorePerHosts = 32;
    final int splitsWanted = numHosts * numCorePerHosts;
    final long start = System.currentTimeMillis() - scanRange;
    long secondsPerSplit = scanRange / (splitsWanted / partitionNum);

    List<long[]> offsetList = new ArrayList<long[]>();
    for (int i = 0; i < splitsWanted / partitionNum; ++i) {
        long[] offsets = new long[2];
        offsets[0] = start + secondsPerSplit * i;
        offsets[1] = start + secondsPerSplit * (i + 1);
        offsetList.add(offsets);
    }
    offsetList.get(offsetList.size() - 1)[1] = OffsetRequest.LatestTime();
    return offsetList;
}
 
开发者ID:dropbox,项目名称:presto-kafka-connector,代码行数:23,代码来源:KafkaSplitSourceProvider.java

示例2: requestAndSetEarliestOrLatestOffsetsFromKafka

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
/**
 * For a set of partitions, if a partition is set with the special offsets {@link OffsetRequest#EarliestTime()}
 * or {@link OffsetRequest#LatestTime()}, replace them with actual offsets requested via a Kafka consumer.
 *
 * @param consumer The consumer connected to lead broker
 * @param partitions The list of partitions we need offsets for
 */
private static void requestAndSetEarliestOrLatestOffsetsFromKafka(
		SimpleConsumer consumer,
		List<KafkaTopicPartitionState<TopicAndPartition>> partitions) throws Exception {
	Map<TopicAndPartition, PartitionOffsetRequestInfo> requestInfo = new HashMap<>();
	for (KafkaTopicPartitionState<TopicAndPartition> part : partitions) {
		if (part.getOffset() == OffsetRequest.EarliestTime() || part.getOffset() == OffsetRequest.LatestTime()) {
			requestInfo.put(part.getKafkaPartitionHandle(), new PartitionOffsetRequestInfo(part.getOffset(), 1));
		}
	}

	requestAndSetOffsetsFromKafka(consumer, partitions, requestInfo);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:SimpleConsumerThread.java

示例3: getInvalidOffsetBehavior

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
/**
 * Retrieve the behaviour of "auto.offset.reset" from the config properties.
 * A partition needs to fallback to "auto.offset.reset" as default offset when
 * we can't find offsets in ZK to start from in {@link StartupMode#GROUP_OFFSETS} startup mode.
 *
 * @param config kafka consumer properties
 * @return either OffsetRequest.LatestTime() or OffsetRequest.EarliestTime()
 */
private static long getInvalidOffsetBehavior(Properties config) {
	final String val = config.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "largest");
	if (val.equals("largest") || val.equals("latest")) { // largest is kafka 0.8, latest is kafka 0.9
		return OffsetRequest.LatestTime();
	} else {
		return OffsetRequest.EarliestTime();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:Kafka08Fetcher.java

示例4: getInvalidOffsetBehavior

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
private static long getInvalidOffsetBehavior(Properties config) {
	final String val = config.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "largest");
	if (val.equals("none")) {
		throw new IllegalArgumentException("Cannot use '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG
				+ "' value 'none'. Possible values: 'latest', 'largest', or 'earliest'.");
	}
	else if (val.equals("largest") || val.equals("latest")) { // largest is kafka 0.8, latest is kafka 0.9
		return OffsetRequest.LatestTime();
	} else {
		return OffsetRequest.EarliestTime();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:FlinkKafkaConsumer08.java

示例5: getTopicLogSize

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
private long getTopicLogSize(String topic, int pid) {
  Option<Object> o = ZkUtils.getLeaderForPartition(zkClient, topic, pid);
  if (o.isEmpty() || o.get() == null) {
    log.error("No broker for partition %s - %s", topic, pid);
    return 0;
  }
  Integer leaderId = Int.unbox(o.get());
  SimpleConsumer consumer = consumerMap.get(leaderId);
  if (consumer == null) {
    consumer = createSimpleConsumer(leaderId);
  }
  // createSimpleConsumer may fail.
  if (consumer == null) {
    return 0;
  }
  consumerMap.put(leaderId, consumer);
  TopicAndPartition topicAndPartition = new TopicAndPartition(topic, pid);
  PartitionOffsetRequestInfo requestInfo = new PartitionOffsetRequestInfo(OffsetRequest.LatestTime(), 1);
  OffsetRequest request = new OffsetRequest(
    new Map1<TopicAndPartition, PartitionOffsetRequestInfo>(topicAndPartition, requestInfo),
    0,
    Request.OrdinaryConsumerId()
  );
  OffsetResponse response = consumer.getOffsetsBefore(request);
  PartitionOffsetsResponse offsetsResponse = response.partitionErrorAndOffsets().get(topicAndPartition).get();
  return scala.Long.unbox(offsetsResponse.offsets().head());
}
 
开发者ID:shunfei,项目名称:DCMonitor,代码行数:28,代码来源:KafkaInfos.java


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