Google云端平台:无法从Container Engine访问Pubsub

Cia*_*her 5 java scala kubernetes google-cloud-pubsub google-kubernetes-engine

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

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

权限

但是,当我尝试运行我的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
Run Code Online (Sandbox Code Playgroud)

全堆栈跟踪这里.

我的Scala代码完全符合快速入门指南:

val TopicName = "my-topic"
val pubsub = PubSubOptions.getDefaultInstance.getService
val topic = pubsub.getTopic(TopicName)
...
topic.publish(Message.of(json))
Run Code Online (Sandbox Code Playgroud)

我想我可能会错过一些重要的Kubernetes配置,所以非常感谢任何和所有的帮助.

小智 3

我发现当 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>
Run Code Online (Sandbox Code Playgroud)