org.apache.kafka.clients.consumer.Consumer.subscription()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中org.apache.kafka.clients.consumer.Consumer.subscription()方法的一些代码示例,展示了Consumer.subscription()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Consumer.subscription()方法的具体详情如下:
包路径:org.apache.kafka.clients.consumer.Consumer
类名称:Consumer
方法名:subscription

Consumer.subscription介绍

暂无

代码示例

代码示例来源:origin: azkaban/azkaban

public Set<String> getMonitorSubscription() {
 return this.consumer.subscription();
}

代码示例来源:origin: openzipkin/brave

@Override public Set<String> subscription() {
 return delegate.subscription();
}

代码示例来源:origin: azkaban/azkaban

/**
 * Dynamically tune subscription only for the topic that dependencies need.
 */
@VisibleForTesting
synchronized void consumerSubscriptionRebalance() {
 log.debug("Subscribed Topics " + this.consumer.subscription());
 if (!this.subscribedTopics.isEmpty()) {
  final Iterator<String> iter = this.subscribedTopics.iterator();
  final List<String> topics = new ArrayList<>();
  while (iter.hasNext()) {
   topics.add(iter.next());
  }
  this.subscribedTopics.clear();
  //re-subscribe topics that are needed
  this.consumer.subscribe(topics);
 }
}

代码示例来源:origin: io.opentracing.contrib/opentracing-kafka-client

@Override
public Set<String> subscription() {
 return consumer.subscription();
}

代码示例来源:origin: opentracing-contrib/java-kafka-client

@Override
public Set<String> subscription() {
 return consumer.subscription();
}

代码示例来源:origin: linkedin/li-apache-kafka-clients

@Override
public Set<String> subscription() {
 return _kafkaConsumer.subscription();
}

代码示例来源:origin: rayokota/kafka-graphs

@Override
public Set<String> subscription() {
  return kafkaConsumer.subscription();
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-kafka-clients

@Override public Set<String> subscription() {
 return delegate.subscription();
}

代码示例来源:origin: vert-x3/vertx-kafka-client

@Override
public KafkaReadStream<K, V> subscription(Handler<AsyncResult<Set<String>>> handler) {
 this.submitTask((consumer, future) -> {
  Set<String> subscription = consumer.subscription();
  if (future != null) {
   future.complete(subscription);
  }
 }, handler);
 return this;
}

代码示例来源:origin: com.cerner.common.kafka/common-kafka

private ConsumerRecords<K, V> pollRecords(long timeout) {
  try {
    long currentTime = System.currentTimeMillis();
    if (lastPollTime != -1L) {
      long pollLatency = currentTime - lastPollTime;
      POLL_LATENCY.update(pollLatency);
      if (pollLatency > config.getMaxPollInterval() && LOGGER.isWarnEnabled()) {
        LOGGER.warn("{}ms has elapsed since last #poll(). This is greater than max.poll.interval.ms {}. If this " +
            "continues you may need to increase max.poll.interval.ms", pollLatency, config.getMaxPollInterval());
      }
    }
    lastPollTime = currentTime;
    return consumer.poll(timeout);
  } catch (IllegalStateException e) {
    // The Kafka consumer will throw this exception if the consumer is not currently subscribed to any topics. Return an
    // empty record collection after verifying that is in fact the case, otherwise rethrow the exception.
    if (consumer.subscription().isEmpty()) {
      LOGGER.debug("Consumer with no subscriptions polled for records.");
      return ConsumerRecords.empty();
    } else {
      throw e;
    }
  }
}

代码示例来源:origin: org.apache.kafka/kafka-streams

private void initialize(final RestoringTasks active) {
  if (!restoreConsumer.subscription().isEmpty()) {
    throw new StreamsException("Restore consumer should not be subscribed to any topics (" + restoreConsumer.subscription() + ")");

代码示例来源:origin: reactor/reactor-kafka

@Test
public void consumerMethods() throws Exception {
  testConsumerMethod(c -> assertEquals(this.assignedPartitions, c.assignment()));
  testConsumerMethod(c -> assertEquals(Collections.singleton(topic), c.subscription()));
  testConsumerMethod(c -> assertEquals(2, c.partitionsFor(topics.get(2)).size()));
  testConsumerMethod(c -> assertEquals(topics.size(), c.listTopics().size()));
  testConsumerMethod(c -> assertEquals(0, c.metrics().size()));
  testConsumerMethod(c -> {
    Collection<TopicPartition> partitions = Collections.singleton(new TopicPartition(topic, 1));
    c.pause(partitions);
    assertEquals(partitions, c.paused());
    c.resume(partitions);
  });
  testConsumerMethod(c -> {
    TopicPartition partition = new TopicPartition(topic, 1);
    Collection<TopicPartition> partitions = Collections.singleton(partition);
    long position = c.position(partition);
    c.seekToBeginning(partitions);
    assertEquals(0, c.position(partition));
    c.seekToEnd(partitions);
    assertTrue("Did not seek to end", c.position(partition) > 0);
    c.seek(partition, position);
  });
}

相关文章