本文整理了Java中org.apache.kafka.clients.consumer.Consumer.commitSync()
方法的一些代码示例,展示了Consumer.commitSync()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Consumer.commitSync()
方法的具体详情如下:
包路径:org.apache.kafka.clients.consumer.Consumer
类名称:Consumer
方法名:commitSync
暂无
代码示例来源:origin: openzipkin/brave
public void commitSync(Duration timeout) {
delegate.commitSync(timeout);
}
代码示例来源:origin: linkedin/cruise-control
@Override
public void onPartitionsRevoked(Collection<TopicPartition> collection) {
_metricConsumer.commitSync();
}
代码示例来源:origin: openzipkin/brave
@Override public void commitSync(Map<TopicPartition, OffsetAndMetadata> offsets) {
delegate.commitSync(offsets);
}
代码示例来源:origin: openzipkin/brave
public void commitSync(Map<TopicPartition, OffsetAndMetadata> offsets, Duration timeout) {
delegate.commitSync(offsets, timeout);
}
代码示例来源:origin: openzipkin/brave
@Override public void commitSync() {
delegate.commitSync();
}
代码示例来源:origin: apache/storm
public static <K, V> void verifyAllMessagesCommitted(Consumer<K, V> consumerSpy,
ArgumentCaptor<Map<TopicPartition, OffsetAndMetadata>> commitCapture, long messageCount) {
verify(consumerSpy, times(1)).commitSync(commitCapture.capture());
Map<TopicPartition, OffsetAndMetadata> commits = commitCapture.getValue();
assertThat("Expected commits for only one topic partition", commits.entrySet().size(), is(1));
OffsetAndMetadata offset = commits.entrySet().iterator().next().getValue();
assertThat("Expected committed offset to cover all emitted messages", offset.offset(), is(messageCount));
}
代码示例来源:origin: apache/storm
consumer.commitSync(nextCommitOffsets);
LOG.debug("Offsets successfully committed to Kafka [{}]", nextCommitOffsets);
代码示例来源:origin: apache/storm
private ConsumerRecords<K, V> pollKafkaBroker(PollablePartitionsInfo pollablePartitionsInfo) {
doSeekRetriableTopicPartitions(pollablePartitionsInfo.pollableEarliestRetriableOffsets);
Set<TopicPartition> pausedPartitions = new HashSet<>(consumer.assignment());
pausedPartitions.removeIf(pollablePartitionsInfo.pollablePartitions::contains);
try {
consumer.pause(pausedPartitions);
final ConsumerRecords<K, V> consumerRecords = consumer.poll(kafkaSpoutConfig.getPollTimeoutMs());
ackRetriableOffsetsIfCompactedAway(pollablePartitionsInfo.pollableEarliestRetriableOffsets, consumerRecords);
final int numPolledRecords = consumerRecords.count();
LOG.debug("Polled [{}] records from Kafka",
numPolledRecords);
if (kafkaSpoutConfig.getProcessingGuarantee() == KafkaSpoutConfig.ProcessingGuarantee.AT_MOST_ONCE) {
//Commit polled records immediately to ensure delivery is at-most-once.
Map<TopicPartition, OffsetAndMetadata> offsetsToCommit =
createFetchedOffsetsMetadata(consumer.assignment());
consumer.commitSync(offsetsToCommit);
LOG.debug("Committed offsets {} to Kafka", offsetsToCommit);
}
return consumerRecords;
} finally {
consumer.resume(pausedPartitions);
}
}
代码示例来源:origin: apache/nifi
kafkaConsumer.commitSync(uncommittedOffsetsMap);
resetInternalState();
return true;
代码示例来源:origin: apache/nifi
kafkaConsumer.commitSync(offsetsMap);
resetInternalState();
return true;
代码示例来源:origin: apache/nifi
kafkaConsumer.commitSync(offsetsMap);
resetInternalState();
return true;
代码示例来源:origin: apache/nifi
kafkaConsumer.commitSync(offsetsMap);
resetInternalState();
return true;
代码示例来源:origin: apache/nifi
kafkaConsumer.commitSync(offsetsMap);
resetInternalState();
return true;
代码示例来源:origin: spring-projects/spring-kafka
@SuppressWarnings("unchecked")
@Test
public void remaingRecordsReceived() throws Exception {
assertThat(this.config.deliveryLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.commitLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.pollLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.errorLatch.await(10, TimeUnit.SECONDS)).isTrue();
InOrder inOrder = inOrder(this.consumer);
inOrder.verify(this.consumer).subscribe(any(Collection.class), any(ConsumerRebalanceListener.class));
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(2L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 1), new OffsetAndMetadata(1L)));
assertThat(this.config.count).isEqualTo(4);
assertThat(this.config.contents).containsExactly("foo", "bar", "baz", "qux");
assertThat(this.config.remaining).containsExactly("qux", "fiz", "buz");
}
代码示例来源:origin: spring-projects/spring-kafka
inOrder.verify(this.consumer).subscribe(any(Collection.class), any(ConsumerRebalanceListener.class));
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(2L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 1), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).seek(new TopicPartition("foo", 1), 1L);
inOrder.verify(this.consumer).seek(new TopicPartition("foo", 2), 0L);
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 1), new OffsetAndMetadata(2L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 2), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 2), new OffsetAndMetadata(2L)));
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
代码示例来源:origin: spring-projects/spring-kafka
@SuppressWarnings("unchecked")
@Test
public void stopContainerAfterException() throws Exception {
assertThat(this.config.deliveryLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.commitLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.pollLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.errorLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.closeLatch.await(10, TimeUnit.SECONDS)).isTrue();
MessageListenerContainer container = this.registry.getListenerContainer(CONTAINER_ID);
assertThat(container.isRunning()).isFalse();
InOrder inOrder = inOrder(this.consumer);
inOrder.verify(this.consumer).subscribe(any(Collection.class), any(ConsumerRebalanceListener.class));
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(2L)));
inOrder.verify(this.consumer).commitSync(
Collections.singletonMap(new TopicPartition("foo", 1), new OffsetAndMetadata(1L)));
inOrder.verify(this.consumer).wakeup();
inOrder.verify(this.consumer).unsubscribe();
inOrder.verify(this.consumer).close();
inOrder.verifyNoMoreInteractions();
assertThat(this.config.count).isEqualTo(4);
assertThat(this.config.contents.toArray()).isEqualTo(new String[]
{ "foo", "bar", "baz", "qux" });
}
代码示例来源:origin: spring-projects/spring-kafka
@SuppressWarnings("unchecked")
@Test
public void discardRemainingRecordsFromPollAndSeek() throws Exception {
assertThat(this.config.deliveryLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.commitLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.pollLatch.await(10, TimeUnit.SECONDS)).isTrue();
this.registry.stop();
assertThat(this.config.closeLatch.await(10, TimeUnit.SECONDS)).isTrue();
InOrder inOrder = inOrder(this.consumer);
inOrder.verify(this.consumer).subscribe(any(Collection.class), any(ConsumerRebalanceListener.class));
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
Map<TopicPartition, OffsetAndMetadata> offsets = new LinkedHashMap<>();
offsets.put(new TopicPartition("foo", 0), new OffsetAndMetadata(2L));
offsets.put(new TopicPartition("foo", 1), new OffsetAndMetadata(1L));
inOrder.verify(this.consumer).commitSync(offsets);
inOrder.verify(this.consumer).seek(new TopicPartition("foo", 1), 1L);
inOrder.verify(this.consumer).seek(new TopicPartition("foo", 2), 0L);
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
offsets = new LinkedHashMap<>();
offsets.put(new TopicPartition("foo", 1), new OffsetAndMetadata(2L));
offsets.put(new TopicPartition("foo", 2), new OffsetAndMetadata(2L));
inOrder.verify(this.consumer).commitSync(offsets);
inOrder.verify(this.consumer).poll(Duration.ofMillis(ContainerProperties.DEFAULT_POLL_TIMEOUT));
assertThat(this.config.count).isEqualTo(7);
assertThat(this.config.contents.toArray()).isEqualTo(new String[]
{ "foo", "bar", "baz", "qux", "qux", "fiz", "buz" });
}
代码示例来源:origin: spring-projects/spring-kafka
this.commitLatch.countDown();
return null;
}).given(consumer).commitSync(any(Map.class));
return consumer;
代码示例来源:origin: spring-projects/spring-kafka
@SuppressWarnings({ "unchecked", "rawtypes" })
@Bean
public KafkaListenerContainerFactory<?> batchSpyFactory() {
ConcurrentKafkaListenerContainerFactory<Integer, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
ConsumerFactory spiedCf = mock(ConsumerFactory.class);
willAnswer(i -> {
Consumer<Integer, CharSequence> spy =
spy(consumerFactory().createConsumer(i.getArgument(0), i.getArgument(1),
i.getArgument(2)));
willAnswer(invocation -> {
try {
return invocation.callRealMethod();
}
finally {
spyLatch.countDown();
}
}).given(spy).commitSync(anyMap());
return spy;
}).given(spiedCf).createConsumer(anyString(), anyString(), anyString());
factory.setConsumerFactory(spiedCf);
factory.setBatchListener(true);
factory.setRecordFilterStrategy(recordFilter());
// always send to the same partition so the replies are in order for the test
factory.setReplyTemplate(partitionZeroReplyingTemplate());
return factory;
}
代码示例来源:origin: spring-projects/spring-kafka
verify(consumer, times(1)).commitSync(anyMap());
container.stop();
verify(consumer, times(2)).commitSync(anyMap());
内容来源于网络,如有侵权,请联系作者删除!