當前位置: 首頁>>代碼示例>>Java>>正文


Java ConsumerConfig.clientId方法代碼示例

本文整理匯總了Java中kafka.consumer.ConsumerConfig.clientId方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsumerConfig.clientId方法的具體用法?Java ConsumerConfig.clientId怎麽用?Java ConsumerConfig.clientId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kafka.consumer.ConsumerConfig的用法示例。


在下文中一共展示了ConsumerConfig.clientId方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConsumeDesc

import kafka.consumer.ConsumerConfig; //導入方法依賴的package包/類
/** 獲取Consumer的描述信息*/
public static String getConsumeDesc(){
	String groupId = getDefaultGroupId();
	ConsumerConfig consumerRealConfig = KafkaHelper.getConsumerRealConfig(groupId);
	return "ZKConnect=(" + consumerRealConfig.zkConnect() + "), groupId=(" + groupId + "), clientId=(" 
		+ consumerRealConfig.clientId() + "), autoOffsetReset=(" + consumerRealConfig.autoOffsetReset() + ")";
}
 
開發者ID:linzhaoming,項目名稱:easyframe-msg,代碼行數:8,代碼來源:MsgUtil.java

示例2: fillInLatestOffsets

import kafka.consumer.ConsumerConfig; //導入方法依賴的package包/類
public static void fillInLatestOffsets(Map<Pair<String,Integer>,Long> offsets,
                                       Map<String,String> kafkaParams) {

  Properties props = new Properties();
  kafkaParams.forEach(props::put);
  ConsumerConfig config = new ConsumerConfig(props);

  Map<Pair<String, Integer>, List<TopicAndPartition>> leaderHostPortToTopicPartition =
      getLeadersForTopicPartitions(offsets, kafkaParams, config);
  
  for (Map.Entry<Pair<String,Integer>,List<TopicAndPartition>> entry : leaderHostPortToTopicPartition.entrySet()) {
    // Connect to leader
    String leaderHost = entry.getKey().getFirst();
    int leaderPort = entry.getKey().getSecond();
    log.info("Connecting to broker {}:{}", leaderHost, leaderPort);
    SimpleConsumer consumer = new SimpleConsumer(
        leaderHost, leaderPort,
        config.socketTimeoutMs(),
        config.socketReceiveBufferBytes(),
        config.clientId());

    try {
      List<TopicAndPartition> topicAndPartitions = entry.getValue();

      // Construct request for latest topic/offsets for each that this leader knows about.
      Map<TopicAndPartition,PartitionOffsetRequestInfo> latestRequests = new HashMap<>();
      Map<TopicAndPartition,PartitionOffsetRequestInfo> earliestRequests = new HashMap<>();
      topicAndPartitions.forEach(tAndP -> {
        latestRequests.put(tAndP, new PartitionOffsetRequestInfo(OffsetRequest$.MODULE$.LatestTime(), 1));
        earliestRequests.put(tAndP, new PartitionOffsetRequestInfo(OffsetRequest$.MODULE$.EarliestTime(), 1));
      });
      OffsetRequest latestRequest = new OffsetRequest(latestRequests,
          OffsetRequest$.MODULE$.CurrentVersion(),
          config.clientId());
      OffsetRequest earliestRequest = new OffsetRequest(earliestRequests,
          OffsetRequest$.MODULE$.CurrentVersion(),
          config.clientId());
      
      OffsetResponse latestResponse = requestOffsets(consumer, latestRequest);
      OffsetResponse earliestResponse = requestOffsets(consumer, earliestRequest);

      // For each topic/partition update, parse and use the values
      topicAndPartitions.forEach(topicPartition -> {
        Long latestTopicOffset = getOffset(latestResponse, topicPartition);
        Pair<String,Integer> topicPartitionKey = new Pair<>(topicPartition.topic(), topicPartition.partition());
        Long currentOffset = offsets.get(topicPartitionKey);
        if (currentOffset == null) {
          if (latestTopicOffset == null) {
            log.info("No initial offset for {}, no latest offset from topic; ignoring");
          } else {
            log.info("No initial offset for {}; using latest offset {} from topic",
                topicPartition, latestTopicOffset);
            offsets.put(topicPartitionKey, latestTopicOffset);
          }
        } else if (latestTopicOffset != null && currentOffset > latestTopicOffset) {
          log.warn("Initial offset {} for {} after latest offset {} from topic! using topic offset",
              currentOffset, topicPartition, latestTopicOffset);
          log.warn("Are you using a stale or incorrect oryx.id?");
          offsets.put(topicPartitionKey, latestTopicOffset);
        } else {
          Long earliestTopicOffset = getOffset(earliestResponse, topicPartition);
          if (earliestTopicOffset != null && currentOffset < earliestTopicOffset) {
            log.warn("Initial offset {} for {} before earliest offset {} from topic! using topic offset",
                currentOffset, topicPartition, earliestTopicOffset);
            log.warn("Are you using a stale or incorrect oryx.id?");
            offsets.put(topicPartitionKey, earliestTopicOffset);
          }
        }
      });

    } finally {
      consumer.close();
    }
  }

  
  offsets.values().removeIf(Objects::isNull);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:79,代碼來源:KafkaUtils.java


注:本文中的kafka.consumer.ConsumerConfig.clientId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。