简体   繁体   中英

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).

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:

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:

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.

I've found that this problem happens when sbt manages the "com-google-cloud-pubsub" dependancy. My work around to this is, I created a maven project and built a jar with only that dependency. Then I added that jar to my classpath and in my build.sbt I annotated the "com-google-cloud-pubsub" as "provided". 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM