【问题标题】:Google Cloud Platform: cannot access Pubsub from Container EngineGoogle Cloud Platform:无法从 Container Engine 访问 Pubsub
【发布时间】:2017-04-26 03:36:28
【问题描述】:

我正在尝试从在 Google Container Engine 中运行的 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

完整的堆栈跟踪here

我的 Scala 代码与快速入门指南差不多:

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

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

【问题讨论】:

标签: java scala kubernetes google-kubernetes-engine google-cloud-pubsub


【解决方案1】:

我发现当 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>

【讨论】:

    猜你喜欢
    • 2017-06-03
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    相关资源
    最近更新 更多