gpt4 book ai didi

java - 谷歌云平台 : cannot access Pubsub from Container Engine

转载 作者:搜寻专家 更新时间:2023-10-31 20:17:37 24 4
gpt4 key购买 nike

我正在尝试从在 Google 容器引擎(即在 Kubernetes 中运行)中运行的 Scala 应用程序发布到现有的 pubsub 主题。

我已经为底层集群启用了(我认为)正确的权限:

permissions

但是,当我尝试运行我的 Scala 应用程序时,出现以下错误:

2016-12-10T22:22:57.811982246Z Caused by:
com.google.cloud.pubsub.PubSubException: java.lang.IllegalStateException:
No NameResolverProviders found via ServiceLoader, including for DNS.
This is probably due to a broken build. If using ProGuard, check your configuration

完整堆栈跟踪 here .

我的 Scala 代码几乎完全来自快速入门指南:

val TopicName = "my-topic"
val pubsub = PubSubOptions.getDefaultInstance.getService
val topic = pubsub.getTopic(TopicName)
...
topic.publish(Message.of(json))

我想我可能遗漏了一些重要的 Kubernetes 配置,因此非常感谢任何和所有帮助。

最佳答案

我发现当 sbt 管理“com-google-cloud-pubsub”依赖项时会发生此问题。我的解决方法是,我创建了一个 Maven 项目并构建了一个仅具有该依赖项的 jar。然后我将该 jar 添加到我的类路径中,并在我的 build.sbt 中将“com-google-cloud-pubsub”注释为“已提供”。我希望这对你有用。

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - 谷歌云平台 : cannot access Pubsub from Container Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41081055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com