当前位置: 首页>>代码示例>>Java>>正文


Java MetadataResponse.TopicMetadata方法代码示例

本文整理汇总了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));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:FetcherTest.java

示例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));
}
 
开发者ID:txazo,项目名称:kafka,代码行数:17,代码来源:FetcherTest.java

示例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;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:InternalTopicManagerTest.java

示例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);
}
 
开发者ID:craftsmenlabs,项目名称:kafka-admin-rest-api,代码行数:15,代码来源:TopicServiceImpl.java

示例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());
}
 
开发者ID:apache,项目名称:kylin,代码行数:16,代码来源:BuildCubeWithStream.java

示例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;
}
 
开发者ID:apache,项目名称:kylin,代码行数:9,代码来源:MockKafka.java

示例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;
}
 
开发者ID:apache,项目名称:kylin,代码行数:34,代码来源:MockKafka.java

示例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();
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:5,代码来源:KafkaUtils.java


注:本文中的org.apache.kafka.common.requests.MetadataResponse.TopicMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。