[英]Google Cloud Platform - unified library
I've started new project in Java and wanted to deploy it on Google Cloud Platform ( not App Engine! ). 我已经开始使用Java启动新项目,并希望将其部署到Google Cloud Platform(而非App Engine!)上。 I also would like to use some of the services/products provided by GCP: Datastore, PubSub etc.
我还想使用GCP提供的某些服务/产品:数据存储区,PubSub等。
I started with the Datastore and found a good library: https://github.com/GoogleCloudPlatform/gcloud-java 我从数据存储开始,找到了一个不错的库: https : //github.com/GoogleCloudPlatform/gcloud-java
Then I decided to start using PubSub and found out that gcloud-java doesn't have anything related to PubSub. 然后我决定开始使用PubSub,发现gcloud-java没有与PubSub相关的任何内容。 Some of the supported libraries for Java PubSub are here: https://cloud.google.com/pubsub/libraries
Java PubSub支持的一些库在这里: https ://cloud.google.com/pubsub/libraries
So, I just wanted to confirm ( because it seems too weird for me ), that Google doesn't have any unified Java library for their services? 因此,我只是想确认一下(因为对我来说似乎太奇怪了),Google没有为其服务提供统一的Java库? And I have no other way than to use two libraries ( with different strategies for managing credentials etc )?
除了使用两个库(使用不同的管理凭据策略)之外,我别无选择吗?
Any help/suggestion would be highly appreciated! 任何帮助/建议将不胜感激! Thank you in advance.
先感谢您。
I don't think you need first lib at all. 我认为您根本不需要首先解放自己。 You need just following:
您只需要遵循以下步骤:
compile "com.google.api-client:google-api-client:1.21.0"
compile "com.google.apis:google-api-services-pubsub:v1-rev8-1.21.0"
And your code will be like: 您的代码将类似于:
HttpTransport httpTransport = new ApacheHttpTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance()
GoogleCredential credentials = GoogleCredential
.fromStream(json)
.createScoped(PubsubScopes.all());
// or on Google Cloud Platform
GoogleCredential credentials = GoogleCredential
.getApplicationDefault(httpTransport, jsonFactory);
Pubsub pubsub = new Pubsub.Builder(httpTransport, jsonFactory, credentials)
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.