本文整理汇总了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);
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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)));
}
示例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)));
}