[英]Google Cloud Platform: cannot access Pubsub from Container Engine
I'm trying to publish to an existing pubsub topic from a Scala application running in Google Container Engine (ie running in Kubernetes). 我正在尝试从运行在Google容器引擎中的Scala应用程序(即在Kubernetes中运行)发布到现有的pubsub主题。
I have enabled (I think) the correct permissions for the underlying cluster: 我已启用(我认为)底层群集的正确权限:
However, when I try run my Scala application, I get the following error: 但是,当我尝试运行我的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
Full stack trace here . 这里有完整的堆栈跟踪
My Scala code is pretty much right out of the quick start guide: 我的Scala代码完全符合快速入门指南:
val TopicName = "my-topic"
val pubsub = PubSubOptions.getDefaultInstance.getService
val topic = pubsub.getTopic(TopicName)
...
topic.publish(Message.of(json))
I think I might be missing some vital Kubernetes configuration, so any and all help is very much appreciated. 我想我可能会错过一些重要的Kubernetes配置,所以非常感谢任何和所有的帮助。
I've found that this problem happens when sbt manages the "com-google-cloud-pubsub" dependancy. 我发现当sbt管理“com-google-cloud-pubsub”依赖时会出现这个问题。 My work around to this is, I created a maven project and built a jar with only that dependency. 我的工作是,我创建了一个maven项目,并构建了一个只有依赖项的jar。 Then I added that jar to my classpath and in my build.sbt I annotated the "com-google-cloud-pubsub" as "provided". 然后我将jar添加到我的classpath和我的build.sbt中,我将“com-google-cloud-pubsub”注释为“提供”。 I hope this works for you. 我希望这适合你。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.