当前位置: 首页>>代码示例>>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;未经允许,请勿转载。