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


Java ListTopicsResponse类代码示例

本文整理汇总了Java中com.google.pubsub.v1.ListTopicsResponse的典型用法代码示例。如果您正苦于以下问题:Java ListTopicsResponse类的具体用法?Java ListTopicsResponse怎么用?Java ListTopicsResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ListTopicsResponse类属于com.google.pubsub.v1包,在下文中一共展示了ListTopicsResponse类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listTopics

import com.google.pubsub.v1.ListTopicsResponse; //导入依赖的package包/类
@Override
public List<TopicPath> listTopics(ProjectPath project) throws IOException {
  ListTopicsRequest.Builder request =
      ListTopicsRequest.newBuilder()
                       .setProject(project.getPath())
                       .setPageSize(LIST_BATCH_SIZE);
  ListTopicsResponse response = publisherStub().listTopics(request.build());
  if (response.getTopicsCount() == 0) {
    return ImmutableList.of();
  }
  List<TopicPath> topics = new ArrayList<>(response.getTopicsCount());
  while (true) {
    for (Topic topic : response.getTopicsList()) {
      topics.add(topicPathFromPath(topic.getName()));
    }
    if (response.getNextPageToken().isEmpty()) {
      break;
    }
    request.setPageToken(response.getNextPageToken());
    response = publisherStub().listTopics(request.build());
  }
  return topics;
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:PubsubGrpcClient.java

示例2: main

import com.google.pubsub.v1.ListTopicsResponse; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {

        if (args.length == 0) {
            System.err.println("Please specify your project name.");
            System.exit(1);
        }
        final String project = args[0];
        ManagedChannelImpl channelImpl = NettyChannelBuilder
            .forAddress("pubsub.googleapis.com", 443)
            .negotiationType(NegotiationType.TLS)
            .build();
        GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
        // Down-scope the credential to just the scopes required by the service
        creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
        // Intercept the channel to bind the credential
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, executor);
        Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
        // Create a stub using the channel that has the bound credential
        PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel);
        ListTopicsRequest request = ListTopicsRequest.newBuilder()
                .setPageSize(10)
                .setProject("projects/" + project)
                .build();
        ListTopicsResponse resp = publisherStub.listTopics(request);
        System.out.println("Found " + resp.getTopicsCount() + " topics.");
        for (Topic topic : resp.getTopicsList()) {
            System.out.println(topic.getName());
        }
    }
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:31,代码来源:Main.java


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