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


Java OffsetRequest.EarliestTime方法代码示例

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


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

示例1: createKafkaSpout

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
/**
 * Creates Kafka spout.
 *
 * @param topic Kafka topic
 * @return {@link KafkaSpout}
 */
protected org.apache.storm.kafka.KafkaSpout createKafkaSpout(String topic, String spoutId) {
    String zkRoot = String.format("/%s/%s", getTopologyName(), topic);
    ZkHosts hosts = new ZkHosts(config.getZookeeperHosts());

    SpoutConfig cfg = new SpoutConfig(hosts, topic, zkRoot, spoutId);
    cfg.startOffsetTime = OffsetRequest.EarliestTime();
    cfg.scheme = new SchemeAsMultiScheme(new StringScheme());
    cfg.bufferSizeBytes = 1024 * 1024 * 4;
    cfg.fetchSizeBytes = 1024 * 1024 * 4;

    return new org.apache.storm.kafka.KafkaSpout(cfg);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:19,代码来源:AbstractTopology.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: getOffsetFromConfigAndDontForceFromStart

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
@Test
public void getOffsetFromConfigAndDontForceFromStart() {
    config.forceFromStart = false;
    config.startOffsetTime = OffsetRequest.EarliestTime();
    createTopicAndSendMessage();
    long latestOffset = KafkaUtils.getOffset(simpleConsumer, config.topic, 0, OffsetRequest.LatestTime());
    long offsetFromConfig = KafkaUtils.getOffset(simpleConsumer, config.topic, 0, config);
    assertThat(latestOffset, is(equalTo(offsetFromConfig)));
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:10,代码来源:KafkaUtilsTest.java

示例6: getOffsetFromConfigAndFroceFromStart

import kafka.api.OffsetRequest; //导入方法依赖的package包/类
@Test
public void getOffsetFromConfigAndFroceFromStart() {
    config.forceFromStart = true;
    config.startOffsetTime = OffsetRequest.EarliestTime();
    createTopicAndSendMessage();
    long earliestOffset = KafkaUtils.getOffset(simpleConsumer, config.topic, 0, OffsetRequest.EarliestTime());
    long offsetFromConfig = KafkaUtils.getOffset(simpleConsumer, config.topic, 0, config);
    assertThat(earliestOffset, is(equalTo(offsetFromConfig)));
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:10,代码来源:KafkaUtilsTest.java


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