java - gcloud-java。权限_拒绝 : Google Cloud Pub/Sub API (Experimental)

标签 java google-app-engine google-cloud-pubsub

我使用gloud-java实验库。今天更新后,出现错误。 从库本地运行示例(这个错误自动出现在谷歌云灵活引擎中,尽管部署一周没有生成)

public class PullTest {
private static final transient Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass().getName());

public static void main(String... args) throws Exception {
    try (PubSub pubsub = PubSubOptions.defaultInstance().service()) {
        String subscriptionName = "subscription-segment";
        Subscription subscription = pubsub.getSubscription(subscriptionName);
    }
}
}

抛出异常

Aug 10, 2016 2:19:08 AM io.grpc.internal.ManagedChannelImpl <init>
INFO: [ManagedChannelImpl@131ef10] Created with target pubsub-experimental.googleapis.com:443
Aug 10, 2016 2:19:08 AM io.grpc.internal.ManagedChannelImpl <init>
INFO: [ManagedChannelImpl@394df057] Created with target pubsub-experimental.googleapis.com:443
Aug 10, 2016 2:19:10 AM io.grpc.internal.ManagedChannelImpl maybeTerminateChannel
INFO: [ManagedChannelImpl@131ef10] Terminated
Exception in thread "main" com.google.cloud.pubsub.PubSubException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Google Cloud Pub/Sub API (Experimental) has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/pubsub-experimental.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
at com.google.cloud.pubsub.spi.DefaultPubSubRpc$1.apply(DefaultPubSubRpc.java:183)
at com.google.cloud.pubsub.spi.DefaultPubSubRpc$1.apply(DefaultPubSubRpc.java:177)
at com.google.common.util.concurrent.Futures$CatchingFuture.doFallback(Futures.java:842)
at com.google.common.util.concurrent.Futures$CatchingFuture.doFallback(Futures.java:834)
at com.google.common.util.concurrent.Futures$AbstractCatchingFuture.run(Futures.java:789)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:634)
at com.google.common.util.concurrent.SettableFuture.setException(SettableFuture.java:53)
at com.google.api.gax.grpc.RetryingCallable$Retryer$1.onFailure(RetryingCallable.java:139)
at com.google.common.util.concurrent.Futures$6.run(Futures.java:1764)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:634)
at com.google.common.util.concurrent.SettableFuture.setException(SettableFuture.java:53)
at com.google.api.gax.grpc.ExceptionTransformingCallable$1.onFailure(ExceptionTransformingCallable.java:90)
at com.google.common.util.concurrent.Futures$6.run(Futures.java:1764)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:634)
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:331)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:307)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$3.runInContext(ClientCallImpl.java:462)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:54)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Google Cloud Pub/Sub API (Experimental) has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/pubsub-experimental.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
... 18 more
Caused by: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Google Cloud Pub/Sub API (Experimental) has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/pubsub-experimental.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
at io.grpc.Status.asRuntimeException(Status.java:503)
... 11 more
Aug 10, 2016 2:19:10 AM io.grpc.internal.ManagedChannelImpl maybeTerminateChannel
INFO: [ManagedChannelImpl@394df057] Terminated

如何解决这个问题? 问题是无缘无故产生的。早上就成功了:)

附注

$gcloud 信息

显示正确的信息

$ gcloud 身份验证登录

没有帮助

最佳答案

(警告:我在为 .NET 构建等效库的团队中工作。这意味着我了解一定数量的所涉及的基础设施,但我不知道任何 Java 特定的细节。)

如果您只是尝试使用 PubSub v1 API,我相信问题在于它连接到 pubsub-experimental.googleapis.com 而不是 pubsub.googleapis.com。我不确定为什么它将其视为默认端点 - default host in the code看起来不错 - 但我相信你应该能够通过手动设置主机来修复它:

PubSubOptions options = PubSubOptions.builder().host("pubsub.googleapis.com").build();
try (PubSub pubsub = options.service()) {
    String subscriptionName = "subscription-segment";
    Subscription subscription = pubsub.getSubscription(subscriptionName);
}

鉴于 github 中的源代码看起来没问题,您可能还想检查一下您是否正在使用该库的最新发布版本...很可能默认主机已在其中修复。根据评论,gcloud-java 0.2.7 默认使用正确的主机。

关于java - gcloud-java。权限_拒绝 : Google Cloud Pub/Sub API (Experimental),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38860888/

相关文章:

java - 解析Android SDK获取ArrayList并返回

java - 如何在单个Gradle测试执行中拥有单元/集成/功能管道

java - Java中存储常量

python - 谷歌应用引擎 webapp2 : No module named pkg_resources error when importing bigquery

google-cloud-pubsub - Google Cloud Pub/Sub 服务是否支持 "data residency"?

java - 如何将 JUnit 测试重定向到 Eclipse 中的控制台?

google-app-engine - 如何使用 Cloud Endpoints 启用 CORS?

python - App-Engine 解析 UrlFetch UTF-8 编码流

java - Google Pub/Sub 主题创建

java - GKE 上的 Google Cloud PubSub : FileNotFoundException while attempting to retrieve the credentials