本文整理汇总了Java中org.apache.kafka.common.requests.MetadataResponse.TopicMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java MetadataResponse.TopicMetadata方法的具体用法?Java MetadataResponse.TopicMetadata怎么用?Java MetadataResponse.TopicMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.common.requests.MetadataResponse
的用法示例。
在下文中一共展示了MetadataResponse.TopicMetadata方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newMetadataResponse
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
private MetadataResponse newMetadataResponse(String topic, Errors error) {
List<MetadataResponse.PartitionMetadata> partitionsMetadata = new ArrayList<>();
if (error == Errors.NONE) {
for (PartitionInfo partitionInfo : cluster.partitionsForTopic(topic)) {
partitionsMetadata.add(new MetadataResponse.PartitionMetadata(
Errors.NONE,
partitionInfo.partition(),
partitionInfo.leader(),
Arrays.asList(partitionInfo.replicas()),
Arrays.asList(partitionInfo.inSyncReplicas())));
}
}
MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(error, topic, false, partitionsMetadata);
return new MetadataResponse(cluster.nodes(), null, MetadataResponse.NO_CONTROLLER_ID, Arrays.asList(topicMetadata));
}
示例2: newMetadataResponse
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
private MetadataResponse newMetadataResponse(String topic, Errors error) {
List<MetadataResponse.PartitionMetadata> partitionsMetadata = new ArrayList<>();
if (error == Errors.NONE) {
for (PartitionInfo partitionInfo : cluster.partitionsForTopic(topic)) {
partitionsMetadata.add(new MetadataResponse.PartitionMetadata(
Errors.NONE,
partitionInfo.partition(),
partitionInfo.leader(),
Arrays.asList(partitionInfo.replicas()),
Arrays.asList(partitionInfo.inSyncReplicas())));
}
}
MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(error, topic, false, partitionsMetadata);
return new MetadataResponse(cluster.nodes(), MetadataResponse.NO_CONTROLLER_ID, Arrays.asList(topicMetadata));
}
示例3: fetchMetadata
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
@Override
public MetadataResponse fetchMetadata() {
Node node = new Node(1, "host1", 1001);
MetadataResponse.PartitionMetadata partitionMetadata = new MetadataResponse.PartitionMetadata(Errors.NONE, 1, node, new ArrayList<Node>(), new ArrayList<Node>());
MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(Errors.NONE, topic, true, Collections.singletonList(partitionMetadata));
MetadataResponse response = new MetadataResponse(Collections.<Node>singletonList(node), null, MetadataResponse.NO_CONTROLLER_ID,
Collections.singletonList(topicMetadata));
return response;
}
示例4: getTopic
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
@Override
public Topic getTopic(final String topicName) {
if (AdminUtils.topicExists(zkUtils, topicName)) {
final MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topicName, zkUtils);
final Topic topic = new Topic();
topic.setName(topicMetadata.topic());
topic.setPartitions(topicMetadata.partitionMetadata().size());
final int replicas = topicMetadata.partitionMetadata().stream().mapToInt(e -> e.replicas().size()).sum();
topic.setReplications(replicas);
topic.setProperties(getTopicProperties(topicName));
return topic;
}
throw new UnknownTopicException(topicName);
}
示例5: startEmbeddedKafka
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
private void startEmbeddedKafka(String topicName, BrokerConfig brokerConfig) {
//Start mock Kakfa
String zkConnectionStr = ZookeeperUtil.getZKConnectString() + kafkaZkPath;
System.out.println("zkConnectionStr" + zkConnectionStr);
zkConnection = new ZkConnection(zkConnectionStr);
// Assert.assertEquals(ZooKeeper.States.CONNECTED, zkConnection.getZookeeperState());
kafkaServer = new MockKafka(zkConnection, brokerConfig.getPort(), brokerConfig.getId());
kafkaServer.start();
kafkaServer.createTopic(topicName, 3, 1);
kafkaServer.waitTopicUntilReady(topicName);
MetadataResponse.TopicMetadata topicMetadata = kafkaServer.fetchTopicMeta(topicName);
Assert.assertEquals(topicName, topicMetadata.topic());
}
示例6: fetchTopicMeta
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
public MetadataResponse.TopicMetadata fetchTopicMeta(String topic) {
ZkClient zkClient = new ZkClient(zkConnection);
ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
zkClient.setZkSerializer(new ZKStringSerializer());
MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils);
zkClient.close();
return topicMetadata;
}
示例7: waitTopicUntilReady
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
public MetadataResponse.TopicMetadata waitTopicUntilReady(String topic) {
boolean isReady = false;
MetadataResponse.TopicMetadata topicMeta = null;
while (!isReady) {
Random random = new Random();
topicMeta = this.fetchTopicMeta(topic);
List<MetadataResponse.PartitionMetadata> partitionsMetadata = topicMeta.partitionMetadata();
Iterator<MetadataResponse.PartitionMetadata> iterator = partitionsMetadata.iterator();
boolean hasGotLeader = true;
boolean hasGotReplica = true;
while (iterator.hasNext()) {
MetadataResponse.PartitionMetadata partitionMeta = iterator.next();
hasGotLeader &= (!partitionMeta.leader().isEmpty());
if (partitionMeta.leader().isEmpty()) {
System.out.println("Partition leader is not ready, wait 1s.");
break;
}
hasGotReplica &= (!partitionMeta.replicas().isEmpty());
if (partitionMeta.replicas().isEmpty()) {
System.out.println("Partition replica is not ready, wait 1s.");
break;
}
}
isReady = hasGotLeader & hasGotReplica;
if (!isReady) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
return topicMeta;
}
示例8: getPartitions
import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
public int getPartitions(String topicName) {
MetadataResponse.TopicMetadata metaData = AdminUtils.fetchTopicMetadataFromZk(topicName, zkUtils);
return metaData.partitionMetadata().size();
}