• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Topic类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
public Topic getTopic(String topicId) {
    if (topicId == null) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Illegal Argument: topic Id is null");
    }
    String topId = (topicId.toLowerCase().startsWith("rapture")) ? topicId : topicId + "rapture";
    Topic topic = topics.get(topId);
    if (topic == null) {
        try (TopicAdminClient topicAdminClient = topicAdminClientCreate()) {
            TopicName topicName = TopicName.create(projectId, topId);
            try {
                topic = topicAdminClient.getTopic(topicName);
            } catch (Exception e) {
                if (topic == null) {
                    topic = topicAdminClient.createTopic(topicName);
                    topics.put(topId, topic);
                }
            }
        } catch (Exception ioe) {
            throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Cannot create or get topic " + topicId, ioe);
        }
    }
    return topic;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:PubsubPipeline2Handler.java


示例2: deleteTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
public void deleteTopic(String topicId) {
    if (topicId == null) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Illegal Argument: topic Id is null");
    }
    String topId = (topicId.toLowerCase().startsWith("rapture")) ? topicId : topicId + "rapture";
    Topic topic = topics.get(topId);
    if (topic != null) {
        try (TopicAdminClient topicAdminClient = topicAdminClientCreate()) {
            TopicName topicName = TopicName.create(projectId, topId);
            topicAdminClient.deleteTopic(topicName);
        } catch (Exception ioe) {
            throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Cannot delete topic " + topicId, ioe);
        }
    }
    topics.remove(topicId);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:PubsubPipeline2Handler.java


示例3: listTopics

import com.google.pubsub.v1.Topic; //导入依赖的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


示例4: createIotTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
/** Creates a topic and grants the IoT service account access. */
public static Topic createIotTopic(String projectId, String topicId) throws Exception {
  // Create a new topic
  final TopicName topicName = TopicName.create(projectId, topicId);

  try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
    final Topic topic = topicAdminClient.createTopic(topicName);
    Policy policy = topicAdminClient.getIamPolicy(topicName.toString());
    // add role -> members binding
    Binding binding =
        Binding.newBuilder()
            .addMembers("serviceAccount:[email protected]")
            .setRole(Role.owner().toString())
            .build();
    // create updated policy
    Policy updatedPolicy = Policy.newBuilder(policy).addBindings(binding).build();
    topicAdminClient.setIamPolicy(topicName.toString(), updatedPolicy);

    System.out.println("Setup topic / policy for: " + topic.getName());
    return topic;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:DeviceRegistryExample.java


示例5: getTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
/**
 * Get the configuration of a Google Cloud Pub/Sub topic.
 *
 * @param topicName canonical topic name, e.g., "topicName"
 * @return topic configuration or {@code null} if topic doesn't exist
 */
public Topic getTopic(String topicName) {
	Assert.hasText(topicName, "No topic name was specified.");

	try {
		return this.topicAdminClient.getTopic(TopicName.create(this.projectId, topicName));
	}
	catch (ApiException aex) {
		if (aex.getStatusCode().getCode() == StatusCode.Code.NOT_FOUND) {
			return null;
		}

		throw aex;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:21,代码来源:PubSubAdmin.java


示例6: listTopics

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
/**
 * Return every topic in a project.
 *
 * <p>If there are multiple pages, they will all be merged into the same result.
 */
public List<Topic> listTopics() {
	PagedResponseWrappers.ListTopicsPagedResponse topicListPage =
			this.topicAdminClient.listTopics(ProjectName.create(this.projectId));

	return Lists.newArrayList(topicListPage.iterateAll());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:12,代码来源:PubSubAdmin.java


示例7: publishTask

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
@Override
public void publishTask(final String queue, final String task) {
    Topic topic = getTopic(queue);
    ByteString data = ByteString.copyFromUtf8(task);
    TopicName topicName = topic.getNameAsTopicName();

    try {
        PubsubMessage psmessage = PubsubMessage.newBuilder().setData(data).build();
        Publisher publisher = randomHouse.get(topicName);
        if (publisher == null) {
            logger.trace("No publisher found for " + topicName + " - creating");
            Builder builder = Publisher.defaultBuilder(topicName);
            // The default executor provider creates an insane number of threads.
            if (executor != null) builder.setExecutorProvider(executor);
            publisher = builder.build();
            randomHouse.put(topicName, publisher);
        } else {
            logger.trace("Existing publisher found for " + topicName);
        }

        ApiFuture<String> messageIdFuture = publisher.publish(psmessage);

        if (executor != null) messageIdFuture.addListener(listener, executor.getExecutor());

    } catch (IOException e) {
        String error = String.format("Cannot send message to topic %s:\n%s", topic.getName(), ExceptionToString.format(e));
        logger.error(error);
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, error, e);
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:31,代码来源:PubsubPipeline2Handler.java


示例8: createTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
@Override
public void createTopic(TopicPath topic) throws IOException {
  Topic request = Topic.newBuilder()
                       .setName(topic.getPath())
                       .build();
  publisherStub().createTopic(request); // ignore Topic result.
}
 
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:PubsubGrpcClient.java


示例9: main

import com.google.pubsub.v1.Topic; //导入依赖的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


示例10: createQueue

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
@Override
public void createQueue(String queueIdentifier) {
    Topic topic = getTopic(queueIdentifier);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:5,代码来源:PubsubPipeline2Handler.java


示例11: TestApp

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
public TestApp()  {

    String projectId = ServiceOptions.getDefaultProjectId();
	try {

		//export GRPC_PROXY_EXP=localhost:3128
		HttpHost proxy = new HttpHost("127.0.0.1",3128);
		DefaultHttpClient httpClient = new DefaultHttpClient();
		httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
					
		httpClient.addRequestInterceptor(new HttpRequestInterceptor(){            
			@Override
			public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException {
					//if (request.getRequestLine().getMethod().equals("CONNECT"))                 
					//   request.addHeader(new BasicHeader("Proxy-Authorization","Basic dXNlcjE6dXNlcjE="));
				}
			});
		
		mHttpTransport =  new ApacheHttpTransport(httpClient);		

		HttpTransportFactory hf = new HttpTransportFactory(){
			@Override
			public HttpTransport create() {
				return mHttpTransport;
			}
		};            
		
		credential = GoogleCredentials.getApplicationDefault(hf);

		CredentialsProvider credentialsProvider =  new GoogleCredentialsProvider(){
			public List<String> getScopesToApply(){
				return Arrays.asList("https://www.googleapis.com/auth/pubsub");
			   }

			public Credentials getCredentials()  {
				return credential;
			}
		};

		TopicAdminSettings topicAdminSettings =
		     TopicAdminSettings.newBuilder().setCredentialsProvider(credentialsProvider)
				 .build();
				 
		 TopicAdminClient topicAdminClient =
		     TopicAdminClient.create(topicAdminSettings);
		
		//TopicAdminClient topicAdminClient = TopicAdminClient.create();
		ProjectName project = ProjectName.create(projectId);
		for (Topic element : topicAdminClient.listTopics(project).iterateAll()) 
	  		System.out.println(element.getName());
	
	} catch (Exception ex) 
	{
		System.out.println("ERROR " + ex);
	}
  }
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:57,代码来源:TestApp.java


示例12: createTopic

import com.google.pubsub.v1.Topic; //导入依赖的package包/类
/**
 * Create a new topic on Google Cloud Pub/Sub.
 *
 * @param topicName the name for the new topic
 * @return the created topic
 */
public Topic createTopic(String topicName) {
	Assert.hasText(topicName, "No topic name was specified.");

	return this.topicAdminClient.createTopic(TopicName.create(this.projectId, topicName));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:12,代码来源:PubSubAdmin.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ImageCacheStatsTracker类代码示例发布时间:2022-05-23
下一篇:
Java DocumentInfo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap