kafka.cluster.Broker.brokerEndPoint()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(141)

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

Broker.brokerEndPoint介绍

暂无

代码示例

代码示例来源:origin: apache/flume

/**
 * Generates the Kafka bootstrap connection string from the metadata stored in Zookeeper.
 * Allows for backwards compatibility of the zookeeperConnect configuration.
 */
private String lookupBootstrap(String zookeeperConnect, SecurityProtocol securityProtocol) {
 try (KafkaZkClient zkClient = KafkaZkClient.apply(zookeeperConnect,
     JaasUtils.isZkSecurityEnabled(), ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT, 10,
     Time.SYSTEM, "kafka.server", "SessionExpireListener")) {
  List<Broker> brokerList =
      JavaConverters.seqAsJavaListConverter(zkClient.getAllBrokersInCluster()).asJava();
  List<BrokerEndPoint> endPoints = brokerList.stream()
      .map(broker -> broker.brokerEndPoint(
        ListenerName.forSecurityProtocol(securityProtocol))
      )
      .collect(Collectors.toList());
  List<String> connections = new ArrayList<>();
  for (BrokerEndPoint endPoint : endPoints) {
   connections.add(endPoint.connectionString());
  }
  return StringUtils.join(connections, ',');
 }
}

代码示例来源:origin: pinterest/doctorkafka

public static String getBrokers(String zkUrl, SecurityProtocol securityProtocol) {
 ZkUtils zkUtils = getZkUtils(zkUrl);
 Seq<Broker> brokersSeq = zkUtils.getAllBrokersInCluster();
 Broker[] brokers = new Broker[brokersSeq.size()];
 brokersSeq.copyToArray(brokers);
 String brokersStr = Arrays.stream(brokers)
   .map(b -> b.brokerEndPoint(
     ListenerName.forSecurityProtocol(securityProtocol)).connectionString())
   .reduce(null, (a, b) -> (a == null) ? b : a + "," + b);
 return brokersStr;
}

代码示例来源:origin: com.github.pinterest/kafkastats

public static String getBrokers(String zkUrl, SecurityProtocol securityProtocol) {
 ZkUtils zkUtils = getZkUtils(zkUrl);
 Seq<Broker> brokersSeq = zkUtils.getAllBrokersInCluster();
 Broker[] brokers = new Broker[brokersSeq.size()];
 brokersSeq.copyToArray(brokers);
 String brokersStr = Arrays.stream(brokers)
   .map(b -> b.brokerEndPoint(
     ListenerName.forSecurityProtocol(securityProtocol)).connectionString())
   .reduce(null, (a, b) -> (a == null) ? b : a + "," + b);
 return brokersStr;
}

代码示例来源:origin: org.apache.flume.flume-ng-sources/flume-kafka-source

/**
 * Generates the Kafka bootstrap connection string from the metadata stored in Zookeeper.
 * Allows for backwards compatibility of the zookeeperConnect configuration.
 */
private String lookupBootstrap(String zookeeperConnect, SecurityProtocol securityProtocol) {
 try (KafkaZkClient zkClient = KafkaZkClient.apply(zookeeperConnect,
     JaasUtils.isZkSecurityEnabled(), ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT, 10,
     Time.SYSTEM, "kafka.server", "SessionExpireListener")) {
  List<Broker> brokerList =
      JavaConverters.seqAsJavaListConverter(zkClient.getAllBrokersInCluster()).asJava();
  List<BrokerEndPoint> endPoints = brokerList.stream()
      .map(broker -> broker.brokerEndPoint(
        ListenerName.forSecurityProtocol(securityProtocol))
      )
      .collect(Collectors.toList());
  List<String> connections = new ArrayList<>();
  for (BrokerEndPoint endPoint : endPoints) {
   connections.add(endPoint.connectionString());
  }
  return StringUtils.join(connections, ',');
 }
}

相关文章